当前位置: 首页 > news >正文

富文本

      let textLabel  = UILabel.init();
        textLabel.frame = CGRect.init(x: 100, y: 100, width: 200, height: 100);
        
        self.view.addSubview(textLabel)
        
        textLabel.textAlignment = .center
        
        
        let attributeString = NSMutableAttributedString.init(string: "你好,我是你哥")
        attributeString.addAttributes([NSAttributedStringKey.paragraphStyle: NSParagraphStyle()], range: NSMakeRange(0, 2))
        attributeString.addAttribute(NSAttributedStringKey.foregroundColor, value: UIColor.red, range:NSMakeRange(0, 3))
        
        attributeString.addAttributes([NSAttributedStringKey.font:UIFont.systemFont(ofSize: 14)], range: NSMakeRange(3, 4));
        textLabel.attributedText = attributeString;
      
复制代码

let attach  = NSTextAttachment.init()
        
        attach.image = UIImage.init(named: "abc_btn_check_to_on_mtrl_015");
        
        attach.bounds = CGRect.init(x: 0, y: -3, width: 20, height: 20)
        let att = NSAttributedString.init(attachment: attach);
        
        attributeString.insert(att, at:0);
          textLabel.attributedText = attributeString;
复制代码

关于NSAttributedStringKey内容如下

public static let font: NSAttributedStringKey

public static let paragraphStyle: NSAttributedStringKey // NSParagraphStyle, default defaultParagraphStyle

public static let foregroundColor: NSAttributedStringKey // UIColor, default blackColor

public static let backgroundColor: NSAttributedStringKey // UIColor, default nil: no background

public static let ligature: NSAttributedStringKey // NSNumber containing integer, default 1: default ligatures, 0: no ligatures

public static let kern: NSAttributedStringKey // NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled.

public static let strikethroughStyle: NSAttributedStringKey // NSNumber containing integer, default 0: no strikethrough

public static let underlineStyle: NSAttributedStringKey // NSNumber containing integer, default 0: no underline

public static let strokeColor: NSAttributedStringKey // UIColor, default nil: same as foreground color

public static let strokeWidth: NSAttributedStringKey // NSNumber containing floating point value, in percent of font point size, default 0: no stroke; positive for stroke alone, negative for stroke and fill (a typical value for outlined text would be 3.0)

public static let shadow: NSAttributedStringKey // NSShadow, default nil: no shadow

public static let textEffect: NSAttributedStringKey // NSString, default nil: no text effect

    
public static let attachment: NSAttributedStringKey // NSTextAttachment, default nil

public static let link: NSAttributedStringKey // NSURL (preferred) or NSString

public static let baselineOffset: NSAttributedStringKey // NSNumber containing floating point value, in points; offset from baseline, default 0

public static let underlineColor: NSAttributedStringKey // UIColor, default nil: same as foreground color

 public static let strikethroughColor: NSAttributedStringKey // UIColor, default nil: same as foreground color

public static let obliqueness: NSAttributedStringKey // NSNumber containing floating point value; skew to be applied to glyphs, default 0: no skew

public static let expansion: NSAttributedStringKey // NSNumber containing floating point value; log of expansion factor to be applied to glyphs, default 0: no expansion

public static let writingDirection: NSAttributedStringKey // NSArray of NSNumbers representing the nested levels of writing direction overrides as defined by Unicode LRE, RLE, LRO, and RLO characters.  The control characters can be obtained by masking NSWritingDirection and NSWritingDirectionFormatType values.  LRE: NSWritingDirectionLeftToRight|NSWritingDirectionEmbedding, RLE: NSWritingDirectionRightToLeft|NSWritingDirectionEmbedding, LRO: NSWritingDirectionLeftToRight|NSWritingDirectionOverride, RLO: NSWritingDirectionRightToLeft|NSWritingDirectionOverride,

public static let verticalGlyphForm: NSAttributedStringKey // An NSNumber containing an integer value.  0 means horizontal text.  1 indicates vertical text.  If not specified, it could follow higher-level vertical orientation settings.  Currently on iOS, it's always horizontal.  The behavior for any other value is undefined.


复制代码

转载于:https://juejin.im/post/5a77c8fb5188254e5c6c4543

相关文章:

  • 记一次monolog的RotatingFileHandler使用
  • pandas中的iloc和loc的区别
  • iOS-多个UIScrollView滑动嵌套(仿微博、抖音、网易云个人详情页)
  • python3基础-字符串
  • 小李飞刀:SQL题目刷起来!
  • CentOS中制作本地yum源
  • 77. Combinations
  • CUDA学习(七)
  • docker同宿主机容器和不同宿主机容器之间怎么通信?
  • Android自定义搜索框,封装了 历史搜索记录功能和样式
  • VuePress 静态网站生成
  • Android中View内部类MeasureSpec研究
  • Java多线程父子线程关系 多线程中篇(六)
  • 使用Nginx、Nginx Plus抵御DDOS攻击
  • 前嗅ForeSpider中数据浏览界面介绍
  • Android单元测试 - 几个重要问题
  • Apache的基本使用
  • CSS3 聊天气泡框以及 inherit、currentColor 关键字
  • docker python 配置
  • Golang-长连接-状态推送
  • Java Agent 学习笔记
  • java2019面试题北京
  • Javascript 原型链
  • MySQL用户中的%到底包不包括localhost?
  • Redis在Web项目中的应用与实践
  • Sass 快速入门教程
  • vue自定义指令实现v-tap插件
  • 工作手记之html2canvas使用概述
  • 基于Dubbo+ZooKeeper的分布式服务的实现
  • 力扣(LeetCode)21
  • 使用 @font-face
  • 试着探索高并发下的系统架构面貌
  • 腾讯视频格式如何转换成mp4 将下载的qlv文件转换成mp4的方法
  • 体验javascript之美-第五课 匿名函数自执行和闭包是一回事儿吗?
  • 线性表及其算法(java实现)
  • 【运维趟坑回忆录】vpc迁移 - 吃螃蟹之路
  • gunicorn工作原理
  • 支付宝花15年解决的这个问题,顶得上做出十个支付宝 ...
  • #LLM入门|Prompt#2.3_对查询任务进行分类|意图分析_Classification
  • $forceUpdate()函数
  • (4)通过调用hadoop的java api实现本地文件上传到hadoop文件系统上
  • (done) ROC曲线 和 AUC值 分别是什么?
  • (PyTorch)TCN和RNN/LSTM/GRU结合实现时间序列预测
  • (分布式缓存)Redis哨兵
  • (九)信息融合方式简介
  • (六)vue-router+UI组件库
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理 第13章 项目资源管理(七)
  • (三)centos7案例实战—vmware虚拟机硬盘挂载与卸载
  • (十八)SpringBoot之发送QQ邮件
  • (十一)c52学习之旅-动态数码管
  • (淘宝无限适配)手机端rem布局详解(转载非原创)
  • (终章)[图像识别]13.OpenCV案例 自定义训练集分类器物体检测
  • (转)利用PHP的debug_backtrace函数,实现PHP文件权限管理、动态加载 【反射】...
  • .bat批处理(十一):替换字符串中包含百分号%的子串
  • .NET Remoting Basic(10)-创建不同宿主的客户端与服务器端