2014-02-22 105 views
1

已经尝试了很多设置的UITextView auotolayout约束。但是当我跑步,我得到空白屏幕。我在UIButton中以相同的方式尝试,这工作!!!!!我如何设置自动布局约束的UITextView的

有没有被设置为UITextView的分配约束任何财产????

UITextView *text1; 
text1=[[UITextView alloc]initWithFrame:CGRectMake(50, 100, 100, 30)]; 
[text1 setBackgroundColor:[UIColor blueColor]]; 
[email protected]"asjdgajsdbasbfbsdfbsdbfbsd"; 

[text1 sizeToFit]; 
set.translatesAutoresizingMaskIntoConstraints=NO; 
[self.view addSubview:text1]; 


NSLayoutConstraint *constraint;  
constraint = [NSLayoutConstraint constraintWithItem:text1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0f constant:1.f]; 

[self.view addConstraint:constraint]; 

回答

3

是喜欢说@你需要更多的约束P.Sami,因为线 set.translatesAutoresizingMaskIntoConstraints=NO; 禁用autoresizeMask它意味着你的框架不能正常工作了。并通过约束条件来聚合所有帧。 在你的事件只是一个约束形容这样的:constraint = [NSLayoutConstraint constraintWithItem:text1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1.0f constant:1.f]; 此约束告诉记者:“像self.view.bottom * 1 + 1 text1.bottom”首先,它的不等于底边的text1和上海华盈,但在1点向下偏移。其次,我们不知道高处怎么样,怀特,x,y? 对于简单的例子只需要添加另外constrints:

[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[text]|" options:0 metrics:nil views:@{text1}]]; 
[self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[text]|" options:0 metrics:nil views:@{text1}]]; 

它告诉text1的像由VERTICALE和Horizo​​ntale self.view框架

+0

非常感谢。 。 。 。 。 –

+0

完全没有。 。 。 。 – Bimawa