1.有时候会遇到 多行显示的比如显示了:金额,时间,日期啥的 这样 不用创建好几个label 一个label 就可以。具体如下:
NSString *str = @"借款金额:200,00元\n借款期限:3个月\n还款方式:等额本息\n放款银行:招商银行尾号1234";
//调整行间距
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:dic[@"detail2"]];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:5];//调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [dic[@"detail2"] length])];
NSDictionary *dicAttribute =@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:Font_Message_CellSubTitle} ;
_lblContentsDetail.numberOfLines = 0;
_lblContentsDetail.lineBreakMode = NSLineBreakByWordWrapping;
_lblContentsDetail.attributedText = attributedString;
//调整高度
CGSize labelDetailSize = [dic[@"detail2"] boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-50,MAXFLOAT)
options:NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin
attributes:dicAttribute
context:nil].size;
_lblContentsDetail.frame = CGRectMake(25, 0, SCREEN_WIDTH - 50, labelDetailSize.height);
2.渐变字体Label
UIColor *titleColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"btn.png"]];
NSString *title = @"Setting";
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 80, 44)];
titleLabel.textColor = titleColor;
titleLabel.text = title;
titleLabel.font = [UIFont boldSystemFontOfSize:20];
titleLabel.backgroundColor = [UIColor clearColor];
[self.view addSubview:titleLabel];