在显示文字时,首先计算显示当前的文字需要多宽和多高,然后将对应的UILabel的大小改变成对应的宽度和高度.
该方法的代码如下:
UILabel *introduceLabel= [[UILabel alloc]init];
CGSize maximumSize = CGSizeMake(screenBounds.size.width-20, 9999);
NSString *dateString = self.businessInfo[0].vendorsIntroduction;
UIFont *dateFont = [UIFont fontWithName:@"Helvetica" size:14];
CGSize dateStringSize = [dateString sizeWithFont:dateFont
constrainedToSize:maximumSize
lineBreakMode:introduceLabel.lineBreakMode];
CGRect dateFrame = CGRectMake(10.0f, 110.0f, screenBounds.size.width-20, dateStringSize.height);
introduceLabel.text = self.businessInfo[0].vendorsIntroduction;
introduceLabel.font = dateFont;
introduceLabel.backgroundColor = [UIColor clearColor];
introduceLabel.lineBreakMode = UILineBreakModeWordWrap;
introduceLabel.numberOfLines = 0;
introduceLabel.frame = dateFrame;
[myscrollview addSubview:introduceLabel];
[introduceLabel release];
转载于:https://blog.51cto.com/2119784/854639