自动调整Label高度\宽度

NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:14],NSForegroundColorAttributeName:[UIColor whiteColor]};
CGSize captionSize = [caption boundingRectWithSize:CGSizeMake(160, 200) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attributes context:nil].size;

NSDictionary *attrs = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:17]};
CGSize size=[_itemNamelabel.text sizeWithAttributes:attrs];
[self.itemNamelabel setFrame:CGRectMake(40, 10, size.width, 20)];

posted @ 2016-08-02 15:08  GJR  阅读(301)  评论(0编辑  收藏  举报