UILabel *noticeLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 100)];
noticeLabel.numberOfLines = 0; // 系統(tǒng)默認(rèn)為1,不加這行不能換行,不換行你就看不出效果
NSString *str1 = @"掃描二維碼\n關(guān)注中國(guó)政府網(wǎng)";
noticeLabel.attributedText = [self attributedStringOfTitleLabel:str1 withFont:[UIFont systemFontSize]];
noticeLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:noticeLabel];
- (NSMutableAttributedString *)attributedStringOfTitleLabel:(NSString *)text withFont:(UIFont *)font{
NSDictionary *attributeDictionary = @{NSKernAttributeName : @(-1.0),NSFontAttributeName:font}; // NSKernAttributeName : @(-1.0) :字間距縮進(jìn)
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text attributes:attributeDictionary];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
//調(diào)整行間距
paragraphStyle.maximumLineHeight = FontHeightTitle(46);
paragraphStyle.minimumLineHeight = FontHeightTitle(46);
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [text length])];
return attributedString;
}
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者