• iOS UILabel自定义行间距


            NSString *hintStr = @"输入材料标题搜索材料
    注:可根据材料序号直接搜索, 如TPO23";
    
            CGSize size = [toolset returnTextStringSizeWithString:hintStr withBoundSize:CGSizeMake(Main_Screen_Width - 72, MAXFLOAT) withFont:FZHei(15)];
    
            self.mHintLabelLayoutH.constant = size.height + 20;
    
            [self.mHitLabel setNeedsLayout];
    
            NSMutableAttributedString *prefixAttr = [[NSMutableAttributedString alloc] initWithString:hintStr];
    
            [prefixAttr addAttribute:NSFontAttributeName value:FZHei(17) range:NSMakeRange(0, hintStr.length)];
    
            [prefixAttr addAttribute:NSForegroundColorAttributeName value:ColorHui range:NSMakeRange(0, hintStr.length)];
    
            [prefixAttr addAttribute:NSForegroundColorAttributeName value:HexRGB(0xc0c0c0) range:NSMakeRange(11, 21)];
    
            [prefixAttr addAttribute:NSFontAttributeName value:FZHei(13) range:NSMakeRange(11, 21)];
    
            NSMutableParagraphStyle *paragraphString = [[NSMutableParagraphStyle alloc] init];
    
            [paragraphString setLineSpacing:8];    //设置行间距
    
            [prefixAttr addAttribute:NSParagraphStyleAttributeName value:paragraphString range:NSMakeRange(0, hintStr.length)];
    
            self.mHitLabel.attributedText = prefixAttr;
     UILabel *dataLabel = [[UILabel alloc] init];
       dataLabel.backgroundColor = [UIColor clearColor];
       dataLabel.text = @"我是文字文字文字文字文字文字文字文字文字文字文字";
       dataLabel.textColor = RGBACOLOR(97, 96, 98, 1);
       dataLabel.font = [UIFont fontWithName:@"Arial" size:14];
       dataLabel.numberOfLines = 0;
       [backImage addSubview:dataLabel];
        
       //富文本设置文字行间距
       NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
       paragraphStyle.lineSpacing = 4;
       NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paragraphStyle};
       dataLabel.attributedText = [[NSAttributedString alloc]initWithString:dataLabel.text attributes:attributes];
        
       //获取设置文本间距以后的高度
       CGRect fram = [dataLabel.attributedText boundingRectWithSize:CGSizeMake(210, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin context:nil];
  • 相关阅读:
    IDEA 2017 安装和破解
    Linux新增开放端口
    ping指定IP的指定端口号
    Ubuntu防火墙常用命令
    Ubuntu端口常用命令
    File Zilla连接Ubuntu 失败
    Docker常用命令详解
    Linux的vi常用命令详解
    Qt事件系统之二:鼠标事件和滚轮事件
    Qt事件系统之一:Qt中的事件处理与传递
  • 原文地址:https://www.cnblogs.com/Milo-CTO/p/4742351.html
Copyright © 2020-2023  润新知