IOS Label 自适应高度

来源:互联网 发布:从零开始学mt4编程 编辑:程序博客网 时间:2024/04/17 00:19

    NSString *str =@"Label自定义高度";

   UIFont *font = [UIFontsystemFontOfSize:13];

   CGSize size =CGSizeMake(320,1000);

    CGRect labelRect = [strboundingRectWithSize:sizeoptions:(NSStringDrawingUsesLineFragmentOriginattributes:[NSDictionarydictionaryWithObject:fontforKey:NSFontAttributeName]context:nil];

   UILabel *label = [[UILabelalloc]initWithFrame:CGRectMake(10,20,300, labelRect.size.height)];

    label.backgroundColor = [UIColorredColor];

    label.text = str;

    label.font = font;

    label.numberOfLines =0;

    [self.viewaddSubview: label];


0 0
原创粉丝点击