Swift NSAttributedString的使用
NSMutableAttributedString
let testAttributes = [NSAttributedStringKey.foregroundColor: UIColor.blue, NSAttributedStringKey.backgroundColor: UIColor.yellow,NSAttributedStringKey.strikethroughStyle:1] as [NSAttributedStringKey : Any]
let testAttributeString = NSAttributedString(string: "富文本测试", attributes:testAttributes)
self.testLabel.attributedText = testAttributeString
let prefix = "¥" + "100"
let suffix = "¥" + "200"
let string = prefix + suffix
let myAttribute = [NSAttributedStringKey.foregroundColor: UIColor.lightGray,
NSAttributedStringKey.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue,
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 13)] as [NSAttributedStringKey : Any]
let redAttribute = [NSAttributedStringKey.foregroundColor: UIColor.red,
NSAttributedStringKey.font: UIFont.systemFont(ofSize: 15)] as [NSAttributedStringKey : Any]
let attString = NSMutableAttributedString(string: string)
attString.addAttributes(redAttribute, range:NSRange.init(location: 0, length: prefix.count))
attString.addAttributes(myAttribute, range: NSRange.init(location: prefix.count, length: suffix.count))
self.titleLabel.attributedText = attString
Swift NSAttributedString的使用的更多相关文章
- NSAttributedString in Swift
转载自: https://www.invasivecode.com/weblog/attributed-text-swift/ I have been talking quite a lot in ...
- swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...
- iOS 下拉刷新和加载更多 (OC\Swift)
Swift语言出来之后, 可能还没有第三方的下拉刷新和上提加载, 所以自己用UIRefreshControl控件和UITableView实例的tableFooterView(底部视图)属性结合起来写了 ...
- iOS开发——实战篇Swift篇&UItableView结合网络请求,多线程,数据解析,MVC实战
UItableView结合网络请求,多线程,数据解析,MVC实战 学了这么久的swift都没有做过什么东西,今天就以自己的一个小小的联系,讲一下,怎么使用swift在实战中应用MVC,并且结合后面的高 ...
- 使用OC和swift创建系统自带的刷新界面
使用OC和swift创建系统自带的刷新界面 一:swift刷新界面代码: import UIKit class ViewController: UITableViewController { // 用 ...
- 转:【iOS开发每日小笔记(十一)】iOS8更新留下的“坑” NSAttributedString设置下划线 NSUnderlineStyleAttributeName 属性必须为NSNumber
http://www.bubuko.com/infodetail-382485.html 标签:des class style 代码 html 使用 问题 文件 数据 ...
- Swift 使用Extension 场景 浅析
别人一看到我的 Swift 代码,立刻就会问我为什么如此频繁的使用 extension.这是前几天在我写的另一篇文章中收到的评论: 我大量使用 extension 的主要目的是为了提高代码可读性.以下 ...
- swift常用第三方库
网络 Alamofire:http网络请求事件处理的框架. Moya:这是一个基于Alamofire的更高层网络请求封装抽象层. Reachability.swift:用来检查应用当前的网络连接状况. ...
- swift UIAlertController使用 UIAlertController的宽度 为270
添加子控件 1. 有标题, alert标题高度大概 是 40, 子控件的 Y一般在40 ,如果中间有换行, \n 的高度大概是30 2.alert的宽度 是270, 设置frame 的时候注意 /// ...
随机推荐
- Json数组转换字符串、字符串转换原数组......
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 网络协议 5 - ICMP 与 ping:投石问路的侦察兵
日常开发中,我们经常会碰到查询网络是否畅通以及域名对应 IP 地址等小需求,这时候用的最多的应该就是 ping 命令了. 那你知道 ping 命令是怎么工作的吗?今天,我们就来一起认识下 pi ...
- 微信扫码登录(3)---授权码code获取用户基本信息
授权码code获取用户基本信息 上一遍已经获得微信回调的code,网址:回调获取code 那这篇通过code和其它参数去获得用户基本信息. 1.UserServiceImpl关键代码 @Ove ...
- java代码之美(10)---Java8 Map中的computeIfAbsent方法
Map中的computeIfAbsent方法 Map接口的实现类如HashMap,ConcurrentHashMap,HashTable等继承了此方法,通过此方法可以在特定需求下,让你的代码更加简洁. ...
- 多机部署redis5.0集群环境
redis5.0集群部署 一.集群介绍 Redis 集群是一个可以在多个 Redis 节点之间进行数据共享的设施(installation). Redis 集群不支持那些需要同时处理多个键的 Redi ...
- Vue轻松入门,一起学起来!
我们创建一个项目,这个项目我们细说Vue. 一.如何在项目中添加模块 我们通过npm 进行 安装 模块. 首先我们通过cmd.exe cd进入你的项目根目录,必须存在package.json文件,安装 ...
- asp.net core系列 40 Web 应用MVC 介绍与详细示例
一. MVC介绍 MVC架构模式有助于实现关注点分离.视图和控制器均依赖于模型. 但是,模型既不依赖于视图,也不依赖于控制器. 这是分离的一个关键优势. 这种分离允许模型独立于可视化展示进行构建和测试 ...
- transient和synchronized的使用
transient和synchronized这两个关键字没什么联系,这两天用到了它们,所以总结一下,两个关键字做个伴! transient 持久化时不被存储,当你的对象实现了Serializable接 ...
- ELK-logstash案例实战之读取日志输出到elasticsearch
简介:从日志文件中读取日志,输出到elasticsearch集群中 $ cd /home/es/logstash-/config $ vim test3_es.conf $ cd /home/es/l ...
- 【ASP.NET Core快速入门】(一)环境安装
下载.NET Core SDK 下载地址:https://www.microsoft.com/net/download/windows https://www.microsoft.com/net/le ...