富文本效果图:

富文本实现代码:

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

        [attributeStr addAttribute:NSForegroundColorAttributeName

                 value:color

                 range:hightlightTextRange];

        [attributeStr addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:14.0f] range:hightlightTextRange];

        return attributeStr;

        }else {

            return [rangeText copy];

            }
}

iOS - 富文本直接设置文字的字体大小和颜色的更多相关文章

  1. iOS富文本组件的实现—DTCoreText源码解析 数据篇

    本文转载 http://blog.cnbang.net/tech/2630/ DTCoreText是个开源的iOS富文本组件,它可以解析HTML与CSS最终用CoreText绘制出来,通常用于在一些需 ...

  2. Axure 文本框去掉边框 富文本 粘贴文字图标

    在今天做原型的过程中,碰到两个问题: 1 文本框该如何去掉边框 2 富文本粘贴文字图标 第一个问题:首先是思路错了,又跑到元件上面找边框,跑到style里面去border的线,结果是不成功. 正解:属 ...

  3. iOS开发之--如何修改TabBarItem的title的字体和颜色/BarButtonItem的title的字体大小和颜色/添加背景图片,并添加点击方法

    在进行项目的过程中,我们往往会遇到各种各样的自定义颜色和字体,下面提供一种修改系统自带的TabBarItem的字体和颜色的方法,希望能帮到大家: [[UITabBarItem appearance] ...

  4. TextView字体大小及颜色设置

    TextView设置文字大小及颜色: 1.1)通过xml配置 <TextView      android:layout_width="match_parent"     a ...

  5. pycharm设置开发模板/字体大小/背景颜色(3)

    一.pycharm设置字体大小/风格 选择 File –> setting –> Editor –> Font ,可以看到如上界面,可以根据自己的喜好随意调整字体大小,字体风格,文字 ...

  6. 修改Xshell字体大小和颜色

    博客专区 > XManager的博客 > 博客详情 修改Xshell字体大小和颜色 XManager 发表于7个月前 分享到: 一键分享 QQ空间 微信 腾讯微博 新浪微博 QQ好友 有道 ...

  7. UISegmentedControl 修改字体大小 和 颜色

    UISegmentedControl 修改字体大小 和 颜色 大小: UIFont *font = [UIFont boldSystemFontOfSize:14.0f]; NSDictionary ...

  8. iOS 开发富文本之TTTAttributedLabel 在某个特定位置的文字添加跳转,下划线,修改字体大小,颜色

    @property(nonatomic , strong) TTTAttributedLabel * ttLabel; @property(nonatomic , strong) NSRange li ...

  9. (转)解决NSMutableAttributedString富文本,不同文字大小水平轴对齐问题(默认底部对齐)

    默认是底部对齐,其实对的也不齐, 目标效果:  代码: NSBaselineOffsetAttributeName 基线偏移量: 调整: NSBaselineOffsetAttributeName的值 ...

随机推荐

  1. [Android Pro] https://blog.csdn.net/gaugamela/article/details/79143309

    原文地址:https://blog.csdn.net/gaugamela/article/details/79143309 最近遇到这样一个问题: 第三方的SDK除了Jar包外,还提供了对应的so文件 ...

  2. 字节码 反编译 APKTool 重新打jar包 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  3. aglio报错解决

    Cannot write or read cache for themes (ENOENT on cache folder) aglio -i ./api.md -o api.html >> ...

  4. CSS全局居中

    可见区域 垂直居中 top:$(document).scrollTop() + ($(document).height() - $(document).scrollTop())/2,

  5. android开发之代码混淆

    在${user.home}/project.properties文件中设置proguard.config属性 # To enable ProGuard to shrink and obfuscate ...

  6. 自建Kubernetes logtail日志采集客户端安装方式

    自建Kubernetes安装方式 前提条件 Kubernetes集群版本1.8及以上. 已经安装Helm命令,版本2.6.4及以上. 安装步骤 在日志服务控制台创建一个Project,Project名 ...

  7. Rplidar学习(四)—— ROS下进行rplidar雷达数据采集源码分析

    一.子函数分析 1.发布数据子函数 (1)雷达数据数据类型 Header header # timestamp in the header is the acquisition time of # t ...

  8. 微信小程序开发填坑

    1.模拟器和真机的差异 在开发的过程中,在模拟器上表现得好好的,在真机上却出问题的例子数不胜数.譬如动画的使用,cover-view上面使用定位,在模拟器好好的,在真机却错乱等等等等.造成这些错乱主要 ...

  9. 源码分析HotSpot GC过程(一)

    «上一篇:源码分析HotSpot GC过程(一)»下一篇:源码分析HotSpot GC过程(三):TenuredGeneration的GC过程 https://blogs.msdn.microsoft ...

  10. ElasticStack系列之九 & master、data 和 client 节点

    在生产环境下,如果不修改elasticsearch节点的角色信息,在高数据量,高并发的场景下集群容易出现脑裂等问题. 默认情况下,elasticsearch 集群中每个节点都有成为主节点的资格,也都存 ...