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即时聊天里面图文并发时可使用该属性进行图文并发

  • 相关阅读:
    单词接龙
    字符串,字符数组
    马的遍历
    约瑟夫问题
    扫雷游戏
    寻找道路
    传纸条
    数的划分
    火柴棒等式
    火星人
  • 原文地址:https://www.cnblogs.com/lszwhb/p/4030845.html
Copyright © 2011-2022 走看看