013-一些开发小技巧

1.动态调整文字大小

NSString *dPriceString  = [NSString stringWithFormat:@"¥%d",model.price]

NSMutableAttributedString *dPrice = [[NSMutableAttributedString alloc] initWithString: dPriceString];
[dPrice addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 12] range: NSMakeRange(0, 1)];
[dPrice addAttribute: NSFontAttributeName value: [UIFont systemFontOfSize: 18] range: NSMakeRange(1, dPriceString.length - 1)];
self.labDiscount.attributedText = dPrice;

 2.使用Label的attributedText属性来显示图片

UIImage *image = [UIImage imageNamed:@"321.jpg"];
    // 1> 生成文本附件
    NSTextAttachment *textAttach = [[NSTextAttachment alloc] init];
    textAttach.image = image;
    // 2> 使用文本附件创建属性文本
    NSAttributedString *strA = [NSAttributedString attributedStringWithAttachment:textAttach];
    self.lblChat.attributedText = strA;

 使用场景:IM即时聊天里面图文并发时可使用该属性进行图文并发

posted on 2014-10-17 13:07  ゴルツの惠斌纳閣下  阅读(175)  评论(0编辑  收藏  举报