ios UITextVIew通过text的内容,来计算UITextView的heigh,因此来调整代码的位置,
下面代码,是提取出来的公用方法,可以参考:
- (void)setScrollViewFrame{
CGSize size = [self.txtViewContent.text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, 1000) lineBreakMode:UILineBreakModeWordWrap];
[txtViewContent setFrame:CGRectMake(self.txtViewContent.frame.origin.x, self.txtViewContent.frame.origin.y, size.width, size.height+43)];
[lblRelativeNews setFrame:CGRectMake(self.lblRelativeNews.frame.origin.x, lbl_y+self.txtViewContent.frame.size.height-0, self.lblRelativeNews.frame.size.width, self.lblRelativeNews.frame.size.height)];
[newsRelatedBtn1 setFrame:CGRectMake(self.newsRelatedBtn1.frame.origin.x, btnFirst_y+self.txtViewContent.frame.size.height-0, self.newsRelatedBtn1.frame.size.width, self.newsRelatedBtn1.frame.size.height)];
[newsRelatedBtn2 setFrame:CGRectMake(self.newsRelatedBtn2.frame.origin.x, btnFirst_y+self.txtViewContent.frame.size.height-0, self.newsRelatedBtn2.frame.size.width, self.newsRelatedBtn2.frame.size.height)];
[newsRelatedBtn3 setFrame:CGRectMake(self.newsRelatedBtn3.frame.origin.x, btnFirst_y+self.txtViewContent.frame.size.height-0, self.newsRelatedBtn3.frame.size.width, self.newsRelatedBtn3.frame.size.height)];
MainScrollView.backgroundColor = [UIColor clearColor];
MainScrollView.contentSize = CGSizeMake(DEVICE_WIDTH, MainScrollView.frame.size.height+self.txtViewContent.frame.size.height+10);
NSLog(@"MainScrollView.contentOffset.x:%f",MainScrollView.contentOffset.x);
NSLog(@"MainScrollView.contentOffset.y:%f",MainScrollView.contentOffset.y);
[MainScrollView setContentOffset:CGPointMake(0, 0) animated:NO];
}