设置字体和颜色

        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 设置 文字字体和大小的更多相关文章

  1. PyCharm如何设置源代码字体的大小

    改源代码大小 1.File→Settings→Editor→Colors&Fonts→Font 2.首先得需要Save as一个Scheme,接下来才可以修改字体,名字可以任意取 改运行字体的 ...

  2. dev richEditControl控件 设置文字 字体 大小

    Document doc = NoticeContentRichEditControl.Document; doc.BeginUpdate(); doc.Text = "需要设置格式的文字& ...

  3. Android中string.xml文件中设置部分字体颜色大小

    1.在string.xml文件中: <string name="tips_all"><Data><![CDATA[清理进程:<font colo ...

  4. 如何设置eclipse字体及大小

    1.打开eclipse菜单栏的Windows选项 2.选择其中的preference选项,界面如下图所示 3.选择General –> Appearance –> Colors and F ...

  5. 【Android初级】使用TypeFace设置TextView的文字字体(附源码)

    在Android里面设置一个TextView的文字颜色和文字大小,都很简单,也是一个常用的基本功能.但很少有设置文字字体的,今天要分享的是通过TypeFace去设置TextView的文字字体,布局里面 ...

  6. 黄聪:phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护

    首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包含了PHPExcel.php和PHPExcel的文件夹,这个类文件和文件夹是我们需要的,把class ...

  7. phpexcel中文教程-设置表格字体颜色背景样式、数据格式、对齐方式、添加图片、批注、文字块、合并拆分单元格、单元格密码保护

    转:http://www.cnblogs.com/huangcong/p/3687665.html 首先到phpexcel官网上下载最新的phpexcel类,下周解压缩一个classes文件夹,里面包 ...

  8. iOS开发-- 设置UIButton的文字显示位置、字体的大小、字体的颜色

    btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...

  9. 设置UIButton的文字显示位置、字体的大小、字体的颜色

    btn.frame = CGRectMake(x, y, width, height); [btn setTitle: @"search" forState: UIControlS ...

随机推荐

  1. Python运算符,基本数据类型

    1,基本的运算符: 加,减,乘,除 取余(%)   取商(//)   **(幂) in    not in (判断是否在里面) 1.运算符        结果是值            算数运算   ...

  2. CSS3 之转动的风车

    js 可以做动画,但是需要写很多代码:其实css也是可以做动画的,而且比js写的代码还少,理解也相对简单. 这里用到css3 的animation 属性,它配合着 @keyframes 规则来使用,可 ...

  3. openwrt中防暴力破解shell的脚本

    原文:http://www.right.com.cn/forum/thread-124429-1-1.html 原理:1. snort做入侵检测是很好,但是太大太复杂,我们需要轻量化的操作.当对方进行 ...

  4. VC++ 中ListCtrl经验总结

    先注明一下,这里,我们用m_listctrl来表示一个CListCtrl的类对象,然后这里我们的ListCtrl都是report形式,至于其他的如什么大图标,小图标的暂时不讲,毕竟report是大众话 ...

  5. 使用 COM 类库创建链接桌面快捷方式

    用到的 COM 类库: Windows Script Host Object Model --> Interop.IWshRuntimeLibrary.dll 示例代码: private sta ...

  6. SQL数据库优化

    1.对查询进行优化,要尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...

  7. /WebRoot/WEB-INF/web.xml

    <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...

  8. biopython

    转载Part 2  Biopython的重头戏-生物学中序列的处理 Biopyhton的Seq和Python中标准字符串有两大重要的不同之处:首先,他们的处理方法不同.Seq适用于很多不同字符串的用的 ...

  9. SpringBoot点滴(1)

    spring boot 注意事项 1.项目启动的主类,放置位置在所有类的外层与controller,dao,service,util,entity同层,SpringBoot会自动扫描@SpringBo ...

  10. msf客户端渗透(五):注册表

    先获取到一个session 上传nc到被攻击主机上 建立一个键值 创建一个策略 kali上查看是否成功创建键值 后台开启cmd 查看防火墙的策略 打开防火墙的端口 添加一条防火墙策略 在win7上查看 ...