UILabel在 scrollview 自适应

来源:互联网 发布:淘宝店铺简介去哪看 编辑:程序博客网 时间:2024/04/28 19:24

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

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


            CGSize maximumLabelSizeOne = CGSizeMake(300,MAXFLOAT);

            

            CGSize labelSize=[productDetailsStringsizeWithFont: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;