首页
学习
活动
专区
工具
TVP
发布

sktj

专栏作者
1542
文章
1894612
阅读量
34
订阅数
IOS 使用Text Kit编排图文
1 let textView = UITextView(frame:CGRect(x:20, y: 40, width:280, height:500)) 2 textView.backgroundColor = UIColor.brown 3 self.view.addSubview(textView) 4 5 let textStorage = textView.textStorage 6 let path = Bundle.main.url(forResource:“word”, withExtension:“txt”) 7 do { 8 let string = try String(contentsOf:path!) 9 textStorage.replaceCharacters(in:NSRange(location: 0,length:0), with:string) 10 } 11 catch{ 12 print(“读取文件错误!”) 13 } 14 let image = UIImage(named:“Tea”) 15 let imageView = UIImageView(image:image) 16 let rect = CGRect(x:80, y:80, width:150, height:
用户5760343
2019-07-10
4420
IOS 使用Text Kit做排版
1 let firstTextView = UITextView(frame:CGRect(x:20, y:40, width:135, height:200)) 2 firstTextView.backgroundColor = UIColor.brown 3 firstTextView.isScrollEnabled = false; 4 self.view.addSubview(firstTextView) 5 let textStorage = firstTextView.textStorage 6 let path = Bundle.main.url(forResource:“word”, withExtension:“txt”) 7 do { 8 let string = try String(contentsOf:path!) 9 textStorage.replaceCharacters(in:NSRange(location: 0,length:0), with:string) 10 } 11 catch{ 12 print(“读取文件错误!”) 13 } 14 let secondRect = CGRect(x:165, y:40, width:135, height:200) 15 let secondTextContainer = NSTextContainer() 16 let secondTextView = UITextView(frame:secondRect, textContainer:secondTextContainer) 17 secondTextView.backgroundColor = UIColor.brown 18 secondTextView.isScrollEnabled = false; 19 self.view.addSubview(secondTextView) 20 let thirdRect = CGRect(x:20, y:250, width:280, height:300) 21 let thirdTextContainer = NSTextContainer() 22 let thirdTextView = UITextView(frame:thirdRect, textContainer:thirdTextContainer) 23 thirdTextView.backgroundColor = UIColor.purple 24 thirdTextView.isScrollEnabled = false; 25 self.view.addSubview(thirdTextView) 26 let layoutManager = NSLayoutManager() 27 layoutManager.addTextContainer(firstTextView.textContainer) 28 layoutManager.addTextContainer(secondTextContainer) 29 layoutManager.addTextContainer(thirdTextContainer) 30 textStorage.addLayoutManager(layoutManager)
用户5760343
2019-07-10
4020
没有更多了
社区活动
腾讯技术创作狂欢月
“码”上创作 21 天,分 10000 元奖品池!
Python精品学习库
代码在线跑,知识轻松学
博客搬家 | 分享价值百万资源包
自行/邀约他人一键搬运博客,速成社区影响力并领取好礼
技术创作特训营·精选知识专栏
往期视频·千货材料·成员作品 最新动态
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档