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];
网友评论