美文网首页
iOS 让Label根据其上的文字属性自适应显示

iOS 让Label根据其上的文字属性自适应显示

作者: LD_左岸 | 来源:发表于2016-08-30 10:45 被阅读269次

    - (void)viewDidLoad {

    [super viewDidLoad];

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 100, 300, 100)];

    label.text = @"fewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdffewfvdf";

    label.numberOfLines = 0;

    label.lineBreakMode = NSLineBreakByWordWrapping;

    CGSize size = [label sizeThatFits:CGSizeMake(label.frame.size.width, MAXFLOAT)];

    label.frame =CGRectMake(10, 100, 300, size.height);

    label.backgroundColor = [UIColor redColor];

    [self.view addSubview:label];

    }

    相关文章

      网友评论

          本文标题:iOS 让Label根据其上的文字属性自适应显示

          本文链接:https://www.haomeiwen.com/subject/pvpfettx.html