iOS 子视图内的像素化文本
pixelated text inside subviews in iOS
当我尝试使用 iPhone 11 Pro Max 模拟器时,文本出现像素化,使用 iPhone 11 Pro 模拟器问题较小,使用 iPhone SE 模拟器没有问题。
信息披露:
- 我使用
将边框添加到文本的顶部块
chartLegendLabel.sizeToFit()
let textWidth = chartLegendLabel.frame.width
let textHeight = chartLegendLabel.frame.height
chartLegendLabel.edgesToSuperview(insets: TinyEdgeInsets(top: barContainerContainer.frame.height - textHeight - 16, left: barContainerContainer.frame.width - textWidth - 16, bottom: 4, right: 4) )
chartLegendLabel.layer.borderColor = UIColor.darkGray.cgColor
chartLegendLabel.layer.borderWidth = 1.0
我刚刚使用 Interface Builder 安排的其他文本。自动调整大小已打开。
非常感谢您的提前帮助
在我的阴影函数中添加了这一行 layer.shouldRasterize = false
(它向文本的超级视图添加了阴影)并且一切正常。
static func shadow(in layer:CALayer){
layer.shadowColor = UIColor.lightGray.cgColor
layer.shadowOffset = CGSize(width:1,height:5)
layer.shadowOpacity = 0.8
layer.shadowRadius = 10
layer.masksToBounds = false
layer.shouldRasterize = false
}
当我尝试使用 iPhone 11 Pro Max 模拟器时,文本出现像素化,使用 iPhone 11 Pro 模拟器问题较小,使用 iPhone SE 模拟器没有问题。
信息披露:
- 我使用 将边框添加到文本的顶部块
chartLegendLabel.sizeToFit()
let textWidth = chartLegendLabel.frame.width
let textHeight = chartLegendLabel.frame.height
chartLegendLabel.edgesToSuperview(insets: TinyEdgeInsets(top: barContainerContainer.frame.height - textHeight - 16, left: barContainerContainer.frame.width - textWidth - 16, bottom: 4, right: 4) )
chartLegendLabel.layer.borderColor = UIColor.darkGray.cgColor
chartLegendLabel.layer.borderWidth = 1.0
我刚刚使用 Interface Builder 安排的其他文本。自动调整大小已打开。
非常感谢您的提前帮助
在我的阴影函数中添加了这一行 layer.shouldRasterize = false
(它向文本的超级视图添加了阴影)并且一切正常。
static func shadow(in layer:CALayer){
layer.shadowColor = UIColor.lightGray.cgColor
layer.shadowOffset = CGSize(width:1,height:5)
layer.shadowOpacity = 0.8
layer.shadowRadius = 10
layer.masksToBounds = false
layer.shouldRasterize = false
}