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 ...
随机推荐
- 使用pt-table-checksum及pt-table-sync校验复制一致性
一.简介 pt-table-checksum是percona-toolkit系列工具中的一个, 可以用来检测主. 从数据库中数据的一致性.其原理是在主库上运行, 对同步的表进行checksum, 记录 ...
- How to Pronounce the Idiom: ‘Out Like a Light’
How to Pronounce the Idiom: ‘Out Like a Light’ Share Tweet Share Tagged With: Idioms English is full ...
- How to Pronounce the Word ARE
How to Pronounce the Word ARE Share Tweet Share Tagged With: ARE Reduction Study the ARE reduction. ...
- fopen函数出现段错误
昨天写代码的时候突然发现了一个问题,当使用fopen("<filepath>", "r")时,如果filepath不存在,那么fopen函数并不是像 ...
- [leetcode]股票题型123
122. Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the price ...
- iptables学习
droidwall.sh #!/system/bin/sh IPTABLES=iptables BUSYBOX=busybox GREP=grep ECHO=echo # Try to find bu ...
- 使用django实现自定义用户认证
参考资料:https://docs.djangoproject.com/en/1.10/topics/auth/customizing/ 直接拉到最后看栗子啦 django自定义用户认证(使用自 ...
- 电脑cpu100%的原因
这个本地系统占很高的cpu,主要原因是我关机之后,没有关透又重启了,就是管了机之后等10几秒再开机会好
- Spring @ControllerAdvice @ExceptionHandler 全局处理异常
对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service 层抛出运行时异常,Spring 事物管理器就会进行回滚. 如此一来, ...
- Webpack Loaders
[Webpack Loaders] 1.Query parameters Loader can be passed query parameters via a query string (just ...