请帮助您了解有关图层及其分辨率的问题。在边线的旋转看起来是阶梯式的
之后,我绘制立方体,每个立方体由三个层(背景,边框和字母)组成let backLayer = CAShapeLayer()
backLayer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
backLayer.bounds = backBounds
backLayer.backgroundColor = color
backLayer.cornerRadius = cornerRadius
backLayer.position = position
backLayer.shadowColor = UIColor.blackColor().CGColor
backLayer.shadowOffset = CGSize(width: shadowWidth, height: shadowWidth)
backLayer.shadowOpacity = 0.5
backLayer.shadowRadius = shadowRadius
backLayer.contentsScale = UIScreen.mainScreen().scale
let subPosition = CGPoint(x: backLayer.bounds.height / 2 + dipper, y: backLayer.bounds.height / 2)
// Border Layer
let borderLayer = CAShapeLayer()
borderLayer.bounds = CGRect(x: 0.0 , y: 0.0, width: backLayer.bounds.width - dipper, height: backLayer.bounds.height)
borderLayer.position = subPosition
borderLayer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
borderLayer.cornerRadius = cornerRadius
borderLayer.borderColor = color
borderLayer.borderWidth = borderWidth
borderLayer.shadowColor = UIColor.blackColor().CGColor
borderLayer.shadowOffset = CGSize(width: 1, height: 1)
borderLayer.shadowRadius = shadowRadius
borderLayer.shadowOpacity = 0.6
borderLayer.contentsScale = UIScreen.mainScreen().scale
// char layer
let charLayer = CATextLayer()
charLayer.bounds = borderLayer.bounds
charLayer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
charLayer.position = subPosition
charLayer.string = NSString(UTF8String: char)
charLayer.alignmentMode = kCAAlignmentCenter
charLayer.wrapped = true
charLayer.shadowColor = UIColor.blackColor().CGColor
charLayer.shadowOffset = CGSize(width: shadowWidth / 3, height: shadowWidth / 3)
charLayer.shadowRadius = 2
charLayer.shadowOpacity = 0.8
charLayer.truncationMode = kCATruncationMiddle
charLayer.font = "BookmanOldStyle-Bold"
charLayer.fontSize = height / 1.4
charLayer.contentsScale = UIScreen.mainScreen().scale
答案 0 :(得分:0)
您可以尝试在图层上启用边缘抗锯齿。像这样:
layer.allowsEdgeAntialiasing = true
如果您想在特定边缘上进行抗锯齿处理(在此示例中仅为左侧和右侧):
layer.edgeAntialiasingMask = [.LayerLeftEdge, .LayerRightEdge]
最后,值得注意的是,如果您愿意,可以在info.plist中全局设置。
密钥为UIViewEdgeAntialiasing
,但要小心,因为the docs" 会对性能产生明显影响"