如何解决PDFKit CGRect 剪切到文本大小 SwiftUI
我想有一个标题,其中 PDF 文档的整个顶部都填充了一种颜色。
无论我将 CGRect 设置为多大以裁剪到文本的边缘,标准行为似乎都是如此。
let attributes = [
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16),NSAttributedString.Key.backgroundColor : UIColor.red,NSAttributedString.Key.foregroundColor : UIColor.white
]
let text = "Hello World!"
text.draw(in: CGRect(x: 0,y: 10,width: 2000,height: 2000),withAttributes: attributes)
见附图。
我做了一个狡猾的解决方案,但对它不满意,因为用户可以复制“空格”而不是实际测试。真的不是一个优雅的解决方案:
let attributes = [
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 16),NSAttributedString.Key.foregroundColor : UIColor.white
]
let attributesBack = [
NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 32),NSAttributedString.Key.foregroundColor : UIColor.white
]
let line = " "
let text = "Hello World!"
line.draw(in: CGRect(x: 0,y: 0,withAttributes: attributesBack)
text.draw(in: CGRect(x: 0,withAttributes: attributes)
Thera 是一种方式吗: 一种。要设置 CGRect 文本被绘制在整个页面上,就像一个 Spacer()? 湾一种绘制实际矩形然后在其上绘制文本的方法?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。