问题描述
我想有一个标题,其中 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 (将#修改为@)