zoukankan      html  css  js  c++  java
  • iOS

    富文本效果图:

    富文本实现代码:

    UILabel *orderSureLabel = [Common lableFrame:CGRectZero title:@"" backgroundColor:[UIColor clearColor] font:[UIFont systemFontOfSize:15] textColor:[UIColor colorWithHexString:@"#666666"]];
        //    orderSureLabel.backgroundColor = [UIColor yellowColor];
        NSMutableAttributedString *orderSureStr = [Common setupAttributeString:@"在主页面下方找到顺道工单,点击“接单”,确认接单。" rangeText:@"顺道工单" textColor:[UIColor colorWithHexString:@"#F34949"]];
        orderSureLabel.attributedText = orderSureStr;
    //    orderSureLabel.text = @"在主页面下方找到顺道工单,点击“接单”,确认接单。";
        orderSureLabel.numberOfLines = 0;
        [self addSubview:orderSureLabel];
        [orderSureLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(orderLabel.mas_bottom).offset(30);
            make.left.equalTo(self).offset(30);
            make.right.equalTo(self).offset(-30);
            make.centerX.equalTo(self);
        }];

    富文本实现的分类方法:

    #pragma mark - 创建UILabel
    
    + (UILabel*)lableFrame:(CGRect)frame title:(NSString *)title backgroundColor:(UIColor*)color font:(UIFont*)font textColor:(UIColor*)textColor {
        
        UILabel *lable=[[UILabel alloc]initWithFrame:frame];
        
        lable.text=title;
        
        lable.font=font;
        
        [lable setBackgroundColor:color];
        
        lable.textColor=textColor;
        
        return lable;
        
    }
    
    #pragma mark - 富文本设置部分字体颜色
    
    + (NSMutableAttributedString *)setupAttributeString:(NSString *)text rangeText:(NSString *)rangeText textColor:(UIColor *)color{
        
        NSRange hightlightTextRange = [text rangeOfString:rangeText];
        
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:text];
        
        if (hightlightTextRange.length > 0) {
            
            [attributeStr addAttribute:NSForegroundColorAttributeName
                     
                     value:color
                     
                     range:hightlightTextRange];
            
            [attributeStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:14.0f] range:hightlightTextRange];
            
            return attributeStr;
            
            }else {
                
                return [rangeText copy];
                
                }
    }
  • 相关阅读:
    如何用Chrome浏览器下载网页音乐视频
    《C语言深度解剖》学习笔记之函数
    《C语言深度解剖》学习笔记之内存管理
    《C语言深度解剖》学习笔记之指针和数组
    《C语言深度解剖》学习笔记之预处理
    《C语言深度解剖》学习笔记之符号
    《C语言深度解剖》学习笔记之关键字
    CKA1.20版本2021年1月31日最新版本真题,第三题升级master节点
    CKA1.20版本2021年1月31日最新版本真题,第一题RBAC
    Linux之curl命令
  • 原文地址:https://www.cnblogs.com/gongyuhonglou/p/10517310.html
Copyright © 2011-2022 走看看