#import <UIKit/UIKit.h>
@interface UILabel (Extension)
+ (UILabel *)labelWithFrame:(CGRect)frame
text:(NSString *)text
textColor:(UIColor *)color
textAlignment:(NSTextAlignment)alignment
font:(UIFont *)font;
//設(shè)置Label的行間距
- (void)setLineSpaceWithString:(CGFloat)lineSpace;
@end
#import "UILabel+Extension.h"
@implementation UILabel (Extension)
+ (UILabel *)labelWithFrame:(CGRect)frame
text:(NSString *)text
textColor:(UIColor *)color
textAlignment:(NSTextAlignment)alignment
font:(UIFont *)font
{
UILabel *label = [[UILabel alloc] initWithFrame:frame];
label.text = text;
label.textColor = color;
label.textAlignment = alignment;
label.font = font;
return label;
}
- (void)setLineSpaceWithString:(CGFloat)lineSpace
{
NSMutableAttributedString *attributedString =
[[NSMutableAttributedString alloc] initWithString:self.text];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:lineSpace];
//調(diào)整行間距
[attributedString addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, [self.text length])];
self.attributedText = attributedString;
}
@end
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者