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];
                
                }
    }
  • 相关阅读:
    darknet yolo 使用gpu
    Application of Opposition-Based Reinforcement Learning in Image Segmentation
    图像质量评估 (IQA) 论文笔记: Deep Neural Networks for No-Reference and Full-Reference Image Quality Assessment
    论文笔记:DEEP LEARNING FOR MONAURAL SPEECH SEPARATION
    python函数中的参数*args和**kwargs的含义和用法
    论文笔记:DualCNN(结构和细节分别训练)
    pytorch中为Module和Tensor指定GPU
    Pytorch中的torch.gather函数的含义
    Django(其二)
    第六章Django
  • 原文地址:https://www.cnblogs.com/gongyuhonglou/p/10517310.html
Copyright © 2011-2022 走看看