现在的位置: 首页 > 综合 > 正文

UILabel在 scrollview 自适应

2013年10月08日 ⁄ 综合 ⁄ 共 1296字 ⁄ 字号 评论关闭

  UIFont *fontOne = [UIFont
systemFontOfSize:15.0];//设置字体大小

            NSString *productDetailsString =[[[[[NSString
stringWithFormat:@"%@",[resultDic
objectForKey:@"productDetails"]]
stringByReplacingOccurrencesOfString:@" "
withString:@""]
stringByReplacingOccurrencesOfString:@"“"
withString:@""]stringByReplacingOccurrencesOfString:@"”"
withString:@""]
stringByReplacingOccurrencesOfString:@"‘"
withString:@""] ;//要显示的内容

            CGSize maximumLabelSizeOne =
CGSizeMake
(300,MAXFLOAT);

            

            CGSize labelSize=[productDetailsString
sizeWithFont:fontOne  constrainedToSize:maximumLabelSizeOne 
lineBreakMode:UILineBreakModeWordWrap];

             if(500+ labelSize.height*labelSize.width/300>1260)

             {

                 scrollview.contentSize =
CGSizeMake(0,600+ labelSize.height*labelSize.width/300);

             }else{

             

                 scrollview.contentSize =
CGSizeMake(0,500+ labelSize.height*labelSize.width/300);

              }

          

            //初始化UILabel

            CGRect pointValueRect =
CGRectMake
(10, 380 ,300, labelSize.height*labelSize.width/300);

            NSLog(@"%f", labelSize.height*labelSize.width/300/30);

            

            detailContent.frame=pointValueRect;

            detailContent.lineBreakMode =
UILineBreakModeWordWrap;

            detailContent.numberOfLines = 0;//上面两行设置多行显示

            detailContent.text=productDetailsString;

            detailContent.sizeToFit;

抱歉!评论已关闭.