zoukankan      html  css  js  c++  java
  • 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即时聊天里面图文并发时可使用该属性进行图文并发

  • 相关阅读:
    队列安排
    杂物
    最大数
    牛券
    斐波那契数列 !有疑惑
    方格取数
    阶乘之和-魏国
    过河卒
    二分查找算法(转)
    求整数的二进制表示中1的个数 (转)
  • 原文地址:https://www.cnblogs.com/lszwhb/p/4030845.html
Copyright © 2011-2022 走看看