美文网首页
attribute属性,富文本属性改变字体

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

作者: 请叫我攻城狮 | 来源:发表于2016-02-21 14:41 被阅读72次

    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属性,富文本属性改变字体

          本文链接:https://www.haomeiwen.com/subject/gwovkttx.html