attribute属性,富文本属性改变字体

NSDictionary *dicM = [NSDictionary dictionary];

NSShadow *shadow = [[NSShadow alloc]init];

shadow.shadowColor = [UIColor purpleColor];

shadow.shadowBlurRadius = 20;

shadow.shadowOffset = CGSizeMake(20, 20);

dicM = @{

NSFontAttributeName : [UIFont fontWithName:@"Arial" size:20],

NSForegroundColorAttributeName : [UIColor redColor],

NSShadowAttributeName: shadow

};

NSAttributedString *str = [[NSAttributedString alloc]initWithString:@"我爱中国" attributes:dicM];

self.lbltext.attributedText = str;


新的方法采用的是 attributes,attributes参数需要的是一个数组

我们常用的有几个

NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];

paragraphStyle.lineBreakMode =NSLineBreakByCharWrapping;

设置对其方式

UIFont *font = [UIFont fontWithName:@"Courier" size:kCellFontSize];

/// Make a copy of the default paragraph style

NSMutableParagraphStyle *paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];

/// Set line break mode

paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;

/// Set text alignment

paragraphStyle.alignment = NSTextAlignmentRight;

NSDictionary *attributes = @{ NSFontAttributeName: font,

NSParagraphStyleAttributeName: paragraphStyle };

[text drawInRect:rect withAttributes:attributes];

你可能感兴趣的:(attribute属性,富文本属性改变字体)