swift - label 的font 设置 文字字体和大小
设置字体和颜色
lab.textColor = UIColor.init(hexColor: "795928")
lab.font = UIFont.systemFont(ofSize: 32, weight: UIFont.Weight.black)
设置html 导图颜色
extension UIColor {
/// 用十六进制颜色创建UIColor
///
/// - Parameter hexColor: 十六进制颜色 (0F0F0F)
convenience init(hexColor: String) {
// 存储转换后的数值
var red:UInt32 = 0, green:UInt32 = 0, blue:UInt32 = 0
// 分别转换进行转换
Scanner(string: hexColor[0..<2]).scanHexInt32(&red)
Scanner(string: hexColor[2..<4]).scanHexInt32(&green)
Scanner(string: hexColor[4..<6]).scanHexInt32(&blue)
self.init(red: CGFloat(red)/255.0, green: CGFloat(green)/255.0, blue: CGFloat(blue)/255.0, alpha: 1.0)
}
convenience init(hexColor: String, alpha: CGFloat) {
// 存储转换后的数值
var red:UInt32 = 0, green:UInt32 = 0, blue:UInt32 = 0
// 分别转换进行转换
Scanner(string: hexColor[0..<2]).scanHexInt32(&red)
Scanner(string: hexColor[2..<4]).scanHexInt32(&green)
Scanner(string: hexColor[4..<6]).scanHexInt32(&blue)
self.init(red: CGFloat(red)/255.0, green: CGFloat(green)/255.0, blue: CGFloat(blue)/255.0, alpha: alpha)
}
}
/// 初始化:十六进制颜色
///
/// - Parameter hexString: 十六进制颜色字符串(1:有#,2:没有#,3:含有0X)
convenience init(hexString: String, alpha: CGFloat = 1.0) {
var cstr = hexString.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased() as NSString
if(cstr.length < 6){
self.init(red: 0, green: 0, blue: 0, alpha: 0)
return
}
if(cstr.hasPrefix("0X")){
cstr = cstr.substring(from: 2) as NSString
}
if(cstr.hasPrefix("#")){
cstr = cstr.substring(from: 1) as NSString
}
if(cstr.length != 6){
self.init(red: 0, green: 0, blue: 0, alpha: 0)
return
}
var range = NSRange.init()
range.location = 0
range.length = 2
let rStr = cstr.substring(with: range)
range.location = 2
let gStr = cstr.substring(with: range)
range.location = 4
let bStr = cstr.substring(with: range)
var r :UInt32 = 0x0
var g :UInt32 = 0x0
var b :UInt32 = 0x0
Scanner.init(string: rStr).scanHexInt32(&r)
Scanner.init(string: gStr).scanHexInt32(&g)
Scanner.init(string: bStr).scanHexInt32(&b)
self.init(red: CGFloat(r)/255.0, green: CGFloat(g)/255.0, blue: CGFloat(b)/255.0, alpha: alpha)
}
swift - label 的font 设置 文字字体和大小的更多相关文章
- PyCharm如何设置源代码字体的大小
改源代码大小 1.File→Settings→Editor→Colors&Fonts→Font 2.首先得需要Save as一个Scheme,接下来才可以修改字体,名字可以任意取 改运行字体的 ...
- dev richEditControl控件 设置文字 字体 大小
Document doc = NoticeContentRichEditControl.Document; doc.BeginUpdate(); doc.Text = "需要设置格式的文字& ...
- Android中string.xml文件中设置部分字体颜色大小
1.在string.xml文件中: <string name="tips_all"><Data><![CDATA[清理进程:<font colo ...
- 如何设置eclipse字体及大小
1.打开eclipse菜单栏的Windows选项 2.选择其中的preference选项,界面如下图所示 3.选择General –> Appearance –> Colors and F ...
- 【Android初级】使用TypeFace设置TextView的文字字体(附源码)
在Android里面设置一个TextView的文字颜色和文字大小,都很简单,也是一个常用的基本功能.但很少有设置文字字体的,今天要分享的是通过TypeFace去设置TextView的文字字体,布局里面 ...
- 黄聪:phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包含了PHPExcel.php和PHPExcel的文件夹,这个类文件和文件夹是我们需要的,把class ...
- phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护
转:http://www.cnblogs.com/huangcong/p/3687665.html 首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包 ...
- iOS开发-- 设置UIButton的文字显示位置、字体的大小、字体的颜色
btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...
- 设置UIButton的文字显示位置、字体的大小、字体的颜色
btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...
随机推荐
- WDA-4-ALV按钮&ICON
1.ICON图标 AccessControlledArea (14x14) Activate (14x14) Active (14x14) AdaptationTechnical (14x14) Ad ...
- Xcode 8 注释快捷键失效
sudo /usr/libexec/xpccachectl 重启
- ACM__搜素之BFS与DFS
BFS(Breadth_First_Search) DFS(Depth_First_Search) 拿图来说 BFS过程,以1为根节点,1与2,3相连,找到了2,3,继续搜2,2与4,相连,找到了4, ...
- Spring Cloud限流详解
转自:https://blog.csdn.net/tracy38/article/details/78685707 在高并发的应用中,限流往往是一个绕不开的话题.本文详细探讨在Spring Cloud ...
- 尚硅谷springboot学习9-配置文件值注入
首先让我想到的是spring的依赖注入,这里我们可以将yaml或者properties配置文件中的值注入到java bean中 配置文件 person: lastName: hello age: 18 ...
- SQL 语句 写法
SELECT * FROM article where userid=4 order by sort asc LIMIT 0,10; 先根据写where 条件,再排序,在LIMIT.
- 26.如何使用python操作我们自己创建的docker image呢?
因为逻辑复杂 我们建个文件来 python #是单行注释 '''是多行注释 或者””” 我们想使用python来操作docker 那么就要一个api https://github.com/docker ...
- Structs复习 Action传递参数
Structs传递参数通常有三种方式 下面我来一个个介绍 1.属性 Jar包 web.xml <?xml version="1.0" encoding="UTF-8 ...
- PR(Precision-Recall)曲线和mAP指标
来自: https://www.zhihu.com/question/41540197 https://www.douban.com/note/518998773/ 作者:水哥链接:https://w ...
- jquery.cookie介绍和用法
1.依赖jQuery库 2.浏览器兼容性情况 3.下载 官方github:https://github.com/carhartl/jquery-cookie 4.使用 创建一个整站cookie $.c ...