我的需求是这样的给宽度自适应label设置圆角,加外边线 且前各留一点距离
//给label赋值
self.status_descLabel.text = model.GroupModel.category_name;
//label字体居中显示
self.status_descLabel.textAlignment = NSTextAlignmentCenter;
//计算label的宽度 然后在加上一点距离 ,并且赋值给label的约束
self.widthLayoutConstraint.constant = [model.GroupModel.category_name boundingRectWithSize:CGSizeMake(260, 14) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14]} context:nil].size.width+15;
//约束立即生效
[self.status_descLabel layoutIfNeeded];
//给label设置圆角 边线 颜色
self.status_descLabel.layer.cornerRadius = 10;
self.status_descLabel.layer.borderWidth = 1;
self.status_descLabel.layer.borderColor = [UIColor greenColor].CGColor;