uilabeL强制换行

UILabel *nickLabel = [[UILabel alloc] init];
nickLabel.font = [UIFont systemFontOfSize:18.0];
NSMutableParagraphStyle paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineBreakMode = NSLineBreakByCharWrapping;
NSDictionary
attribute=@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSParagraphStyleAttributeName:paragraphStyle.copy};
CGSize sizename=[nickLabel.text boundingRectWithSize:CGSizeMake(DWDeviceW-40, 80) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size;
nickLabel.lineBreakMode=NSLineBreakByCharWrapping;
nickLabel.lineBreakMode=0;
nickLabel.backgroundColor=[UIColor redColor];
[self addSubview:nickLabel];
[nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@
);
make.left.equalTo(@((DWDeviceW-sizename.width-80)/2));
make.width.equalTo(@(sizename.width+80));
make.height.equalTo(@25);
}];

你可能感兴趣的:(uilabeL强制换行)