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];
                
                }
    }
  • 相关阅读:
    Android Touch事件的分发过程
    使用runOnUiThread更新UI
    Sqlite访问数据库很慢的问题
    资源收集
    mongdb shard集群均衡导致宿主机CPU飙到100%处理
    Harbor安装
    springboot 启动脚本获取pid问题
    androidstudio build 时间太长处理
    修改 Docker 的 daemon.json后启动失败
    关于在centos7 64为引用android so引发的问题修复
  • 原文地址:https://www.cnblogs.com/gongyuhonglou/p/10517310.html
Copyright © 2011-2022 走看看