iOS自动换行

其实只需要一句话:label.numberOfLines=0;


UILabel *tipLabel = [[UILabel alloc] init];

 tipLabel.textAlignment = NSTextAlignmentLeft;

 tipLabel.backgroundColor = [UIColor clearColor];

 tipLabel.font= [UIFontfontWithName:font_yuantisize:20];

 tipLabel.text = @"欢迎光临,我的朋友们,这里是“凌冬将至,夕阳已沉”的胡言乱语";

 NSDictionary *attribute = @{NSFontAttributeName: [UIFont fontWithName:font_yuanti size:20]};

CGSize labelSize = [tipLabel.text boundingRectWithSize:CGSizeMake(200, 5000) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;

tipLabel.frame = CGRectMake(33, CGRectGetHeight(self.view.frame)/2.0-SafeAreaTopHeight*2, CGRectGetWidth(self.view.frame)-66, labelSize.height);

tipLabel.numberOfLines=0;

tipLabel.textColor= [UIColorcolorWithHexString:@"#000000"];

[_tableViewaddSubview:tipLabel];

你可能感兴趣的:(iOS自动换行)