设置字体和颜色

        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. RabbitMQ系列教程之五:主题(Topic)(转载)

    RabbitMQ系列教程之五:主题(Topic) (本实例都是使用的Net的客户端,使用C#编写),说明,中文方括号[]表示名词. 在上一个教程中,我们改进了我们的日志记录系统. 没有使用只能够进行虚 ...

  2. 如何配置windows定时任务

    Windows上配置任务定时执行有两种方法.一是通过控制面板中的界面配置,另外一种是通过schtasks命令配置.如果是简单的定时任务配置(比如每天单次执行)建议选择界面的方式,简洁.直观.易上手.如 ...

  3. editable : false与 readonly 的区别

    editable : false 不能输入 readonly:不可操作,只能看

  4. arcgis_SDE安装步骤

    弄了将近一个星期的Oracle和ArcSDE终于让我给弄好了!下面把过程跟大家分享一下: 首先是Oracle10gR2的安装,在Oracle的官方网站上可以下到Oracle10gR2的安装程序,安装过 ...

  5. 吴裕雄 python 机器学习-KNN(2)

    import matplotlib import numpy as np import matplotlib.pyplot as plt from matplotlib.patches import ...

  6. vue如果是首页了 不让其后退

    history.pushState(null, null, document.URL); //首页加载时候先置空 window.addEventListener('popstate', functio ...

  7. zabbix 利用python脚本实现钉钉告警

    Zabbix 利用python脚本实现钉钉告警 1.安装python3.6环境 2.创建python脚本 cd local/zabbix-4.0.3/share/zabbix/alertscripts ...

  8. AssetBundle Manager

    [AssetBundle Manager] AssetBundleManager是一个款Unity公司制作的Unity库. 1.Simulation Mode The main advantage o ...

  9. app.use

    [app.use] app.use([path,] function [, function...]) Mounting a middleware at a path will cause the m ...

  10. C#单例和Unity单例

    单例是一种设计模式 单例:不管在项目中的任何模块,当需要使用某个对象的时候,获取到的始终是同一个对象 在C#中 public class InstanceDemo{ private static In ...