首页 > 移动平台 > 详细

iOS富文本的使用

时间:2016-10-10 19:37:54      阅读:152      评论:0      收藏:0      [点我收藏+]

    NSString *name = nil;

    if (_payNumber == 1) { 

 

        name = [NSString stringWithFormat:@"向%@收款",nameStr];

    }else if (_payNumber == 2){  

    

        name = [NSString stringWithFormat:@"向%@付款",nameStr];

    }

 

    //富文本

    NSMutableAttributedString *abs = [[NSMutableAttributedString alloc] initWithString:name];

 

    shopNameLabel = [[UILabel alloc] init];

    shopNameLabel.font = [UIFont systemFontOfSize:17];

    shopNameLabel.textColor = [UIColor colorWithHexString:@"#666666"];

    //字体加粗

    [abs addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:17.0] range:NSMakeRange(1, nameStr.length)];

    //颜色

    [abs addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"#333333"] range:NSMakeRange(1, nameStr.length)];

    

    shopNameLabel.attributedText = abs;

    [shopNameLabel sizeToFit];     //取shopNameLabel.frame.size.width

 

    shopNameLabel.frame = CGRectMake((self.view.frame.size.width - shopNameLabel.frame.size.width)/ 2, shopLogoImg.frame.size.height + shopLogoImg.frame.origin.y + 15, shopNameLabel.frame.size.width, 25);

    shopNameLabel.textAlignment = NSTextAlignmentCenter;

    [shopInfoView addSubview:shopNameLabel];

iOS富文本的使用

原文:http://www.cnblogs.com/ios988/p/5946317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!