#import <UIKit/UIKit.h>
@interface UILabel (Extension)
+ (UILabel *)labelWithFrame:(CGRect)frame
text:(NSString *)text
textColor:(UIColor *)color
textAlignment:(NSTextAlignment)alignment
font:(UIFont *)font;
//设置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];
//调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, [self.text length])];
self.attributedText = attributedString;
}
@end