【发布时间】:2014-03-19 05:56:39
【问题描述】:
我有一个自定义 UIView,我想在其中布局一组 UITextView 以响应 AJAX 调用。所以我想我需要在代码中创建这些。我目前将位置设置为固定位置,但宁愿将其设置为比前一个位置低 20 像素。另外,我想将我的 UITextView 的最小宽度设置为 650 像素。我正在使用 AutoLayout,但对实现此目的的最佳方法感到困惑。我已经包含了我的代码,但我真的在寻找最适合实现这一目标的策略?使用自动布局约束?
我已经包含了我当前的操作方式,但想解决动态垂直放置和 UITextView 的固定宽度为 650 点的问题。非常感谢策略或代码方面的任何帮助。
for (int i = 0; i < [some count]; i++) {
int my_counter=i+1;
// this is obviously putting it a fixed location
UITextView *textview= [[UITextView alloc]initWithFrame:CGRectMake(110, (130 * my_counter), 650, 90)];
[textview setScrollEnabled:YES];
textview.layer.borderWidth = 5.0f;
textview.layer.borderColor = [[UIColor grayColor] CGColor];
[textview setTextContainerInset:UIEdgeInsetsMake(7, 7, 7, 7)];
NSString *tmp_header=[some[i] objectForKey:@"header"];
NSString *tmp_body=[some[i] objectForKey:@"body"];
//NSString *str = @"This is <font color='red'>simple</font>";
if(![tmp_header isEqualToString:@""] && ![tmp_body isEqualToString:@""]){
NSString *myString=[NSString stringWithFormat:@"%@ \n %@", tmp_header, tmp_body];
[textview setValue:myString forKey:@"contentToHTMLString"];
}
if([tmp_header isEqualToString:@""] && ![tmp_body isEqualToString:@""]){
[textview setValue:@"body is cool" forKey:@"contentToHTMLString"];
}
textview.textAlignment = NSTextAlignmentLeft;
textview.editable = NO;
textview.font = [UIFont fontWithName:@"vardana" size:20.0];
[textview sizeToFit];
[textview setScrollEnabled:NO];
//textview.contentSize.width=650;
[self.noteView addSubview:textview];
}
【问题讨论】:
-
我认为最好的办法是通过代码添加约束..
标签: ios objective-c ios7 uitextview