前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >IOS 改变字体样式 **

IOS 改变字体样式 **

作者头像
用户5760343
发布2019-07-10 15:46:56
1.5K0
发布2019-07-10 15:46:56
举报
文章被收录于专栏:sktjsktj

1 import UIKit 2 import CoreText 3 4 class ViewController:UIViewController { 5 6 override func viewDidLoad() { 7 super.viewDidLoad() 8 // Do any additional setup after loading the view, typically from a nib. 9 10 let label = UILabel(frame:CGRect(x:10, y:60, width:300, height:40)) 11 let string = NSMutableAttributedString(string:“Interactive tutorials for Xcode”) 12 13 let font = CTFontCreateWithName(“CourierNewPSBoldMT” as CFString?, 22, nil) 14 string.addAttribute(kCTFontAttributeName as String, value:font, range:NSRange(location:0, length:11)) 15 16 var number = 3 17 let cfNumber = CFNumberCreate(kCFAllocatorDefault, CFNumberType.sInt8Type, &number) 18 string.addAttribute(kCTStrokeWidthAttributeName as String, value:cfNumber!, range: NSMakeRange(12, 9)) 19 20 let italicFont = UIFont.italicSystemFont(ofSize:14) 21 let fontValue = CTFontCreateWithName(italicFont.fontName as CFString?, 14, nil) 22 string.addAttribute(kCTFontAttributeName as String, value:fontValue, range: NSRange(location:22, length:3)) 23 24 string.addAttribute(kCTUnderlineStyleAttributeName as String, value:NSNumber(value:1), range: NSRange(location:26, length:5)) 25 26 label.attributedText = string 27 self.view.addSubview(label) 28 } 29 }

image.png

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.07.06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
文件存储
文件存储(Cloud File Storage,CFS)为您提供安全可靠、可扩展的共享文件存储服务。文件存储可与腾讯云服务器、容器服务、批量计算等服务搭配使用,为多个计算节点提供容量和性能可弹性扩展的高性能共享存储。腾讯云文件存储的管理界面简单、易使用,可实现对现有应用的无缝集成;按实际用量付费,为您节约成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档