项目截图
还是项目需求,上面两个都是textview,内容多了,textview的高自动变高!!!直接上代码!!!
@interface ViewController ()<UITextViewDelegate>
{
UITextView *textview1;
UITextView *textview;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
textview = [[UITextView alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 40)];
textview.backgroundColor = [UIColor redColor];
textview.font = [UIFont systemFontOfSize:20];
textview.delegate = self;
[self.view addSubview:textview];
textview1 = [[UITextView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(textview.frame), self.view.frame.size.width, 40)];
textview1.backgroundColor = [UIColor cyanColor];
textview1.font = [UIFont systemFontOfSize:20];
textview1.delegate = self;
[self.view addSubview:textview1];
}
-(void)textViewDidChange:(UITextView *)textView{
CGSize size = [textView sizeThatFits:CGSizeMake(self.view.frame.size.width, MAXFLOAT)];
if (size.height<=36) {
textView.scrollEnabled = NO;
}else{
textView.scrollEnabled = YES;
}
textView.frame = CGRectMake(0, 100,self.view.frame.size.width, size.height);
NSLog(@"%f",size.height);
// CGFloat cha = size.height - 40;
textview1.frame = CGRectMake(0, CGRectGetMaxY(textview.frame),self.view.frame.size.width , 40);
}
网友评论