ios UITextVIew通过text的内容,来计算UITextView的heigh,因此来调整代码的位置

来源:互联网 发布:merline mac 破解版 编辑:程序博客网 时间:2024/06/07 20:52

ios UITextVIew通过text的内容,来计算UITextView的heigh,因此来调整代码的位置,

下面代码,是提取出来的公用方法,可以参考:

- (void)setScrollViewFrame{

    CGSize  size = [self.txtViewContent.textsizeWithFont:[UIFontsystemFontOfSize: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 = [UIColorclearColor];

    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); 

    


    [MainScrollViewsetContentOffset:CGPointMake(0,0) animated:NO];

}

原创粉丝点击