我的需求是這樣的給寬度自適應(yīng)label設(shè)置圓角挤茄,加外邊線 且前各留一點(diǎn)距離
//給label賦值
self.status_descLabel.text = model.GroupModel.category_name;
//label字體居中顯示
self.status_descLabel.textAlignment = NSTextAlignmentCenter;
//計(jì)算label的寬度 然后在加上一點(diǎn)距離 睡榆,并且賦值給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設(shè)置圓角 邊線 顏色
self.status_descLabel.layer.cornerRadius = 10;
self.status_descLabel.layer.borderWidth = 1;
self.status_descLabel.layer.borderColor = [UIColor greenColor].CGColor;