基本上是我的问题。在我的iOS设备上,我看到这颗颗粒状的图标。 imageView是35px。使用下面的代码绘制图标。我不明白为什么aspectFit让这个图标看起来如此糟糕?我也尝试添加简单的图像资产,即使它看起来一样。任何想法都错了吗?
func drawSocialfacebookoutline(frame targetFrame: CGRect = CGRect(x: 0, y: 0, width: 512, height: 512), resizing: ResizingBehavior = .aspectFit) {
//// General Declarations
let context = UIGraphicsGetCurrentContext()!
//// Resize to Target Frame
context.saveGState()
let resizedFrame: CGRect = resizing.apply(rect: CGRect(x: 0, y: 0, width: 512, height: 512), target: targetFrame)
context.translateBy(x: resizedFrame.minX, y: resizedFrame.minY)
context.scaleBy(x: resizedFrame.width / 512, y: resizedFrame.height / 512)
//// Bezier Drawing
let bezierPath = UIBezierPath()
bezierPath.move(to: CGPoint(x: 288, y: 192))
bezierPath.addLine(to: CGPoint(x: 288, y: 153.9))
bezierPath.addCurve(to: CGPoint(x: 318.5, y: 128), controlPoint1: CGPoint(x: 288, y: 136.7), controlPoint2: CGPoint(x: 291.8, y: 128))
bezierPath.addLine(to: CGPoint(x: 352, y: 128))
bezierPath.addLine(to: CGPoint(x: 352, y: 64))
bezierPath.addLine(to: CGPoint(x: 296.1, y: 64))
bezierPath.addCurve(to: CGPoint(x: 205, y: 149.3), controlPoint1: CGPoint(x: 227.6, y: 64), controlPoint2: CGPoint(x: 205, y: 95.4))
bezierPath.addLine(to: CGPoint(x: 205, y: 192))
bezierPath.addLine(to: CGPoint(x: 160, y: 192))
bezierPath.addLine(to: CGPoint(x: 160, y: 256))
bezierPath.addLine(to: CGPoint(x: 205, y: 256))
bezierPath.addLine(to: CGPoint(x: 205, y: 448))
bezierPath.addLine(to: CGPoint(x: 288, y: 448))
bezierPath.addLine(to: CGPoint(x: 288, y: 256))
bezierPath.addLine(to: CGPoint(x: 344.4, y: 256))
bezierPath.addLine(to: CGPoint(x: 352, y: 192))
bezierPath.addLine(to: CGPoint(x: 288, y: 192))
bezierPath.close()
bezierPath.move(to: CGPoint(x: 330.2, y: 240))
bezierPath.addLine(to: CGPoint(x: 289.1, y: 240))
bezierPath.addLine(to: CGPoint(x: 272, y: 240))
bezierPath.addLine(to: CGPoint(x: 272, y: 255.5))
bezierPath.addLine(to: CGPoint(x: 272, y: 432))
bezierPath.addLine(to: CGPoint(x: 221, y: 432))
bezierPath.addLine(to: CGPoint(x: 221, y: 255.5))
bezierPath.addLine(to: CGPoint(x: 221, y: 240))
bezierPath.addLine(to: CGPoint(x: 206.1, y: 240))
bezierPath.addLine(to: CGPoint(x: 176, y: 240))
bezierPath.addLine(to: CGPoint(x: 176, y: 208))
bezierPath.addLine(to: CGPoint(x: 206.1, y: 208))
bezierPath.addLine(to: CGPoint(x: 221, y: 208))
bezierPath.addLine(to: CGPoint(x: 221, y: 191.5))
bezierPath.addLine(to: CGPoint(x: 221, y: 149.3))
bezierPath.addCurve(to: CGPoint(x: 236.5, y: 97.5), controlPoint1: CGPoint(x: 221, y: 124.8), controlPoint2: CGPoint(x: 226.4, y: 108.1))
bezierPath.addCurve(to: CGPoint(x: 296.1, y: 80), controlPoint1: CGPoint(x: 247.7, y: 85.5), controlPoint2: CGPoint(x: 267.6, y: 80))
bezierPath.addLine(to: CGPoint(x: 336, y: 80))
bezierPath.addLine(to: CGPoint(x: 336, y: 112))
bezierPath.addLine(to: CGPoint(x: 318.5, y: 112))
bezierPath.addCurve(to: CGPoint(x: 281.4, y: 123.7), controlPoint1: CGPoint(x: 306.5, y: 112), controlPoint2: CGPoint(x: 291, y: 113.1))
bezierPath.addCurve(to: CGPoint(x: 272, y: 153.8), controlPoint1: CGPoint(x: 273.3, y: 132.7), controlPoint2: CGPoint(x: 272, y: 143.8))
bezierPath.addLine(to: CGPoint(x: 272, y: 191.4))
bezierPath.addLine(to: CGPoint(x: 272, y: 208))
bezierPath.addLine(to: CGPoint(x: 289.1, y: 208))
bezierPath.addLine(to: CGPoint(x: 334, y: 208))
bezierPath.addLine(to: CGPoint(x: 330.2, y: 240))
bezierPath.close()
DKStyleKit.dkBlue.setFill()
bezierPath.fill()
context.restoreGState()
}
然后是将draw方法转换为UIImage:
public dynamic class var imageOfSocialfacebookoutline: UIImage {
if Cache.imageOfSocialfacebookoutline != nil {
return Cache.imageOfSocialfacebookoutline!
}
UIGraphicsBeginImageContextWithOptions(CGSize(width: 512, height: 512), false, 0)
DKStyleKit.drawSocialfacebookoutline()
Cache.imageOfSocialfacebookoutline = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return Cache.imageOfSocialfacebookoutline!
}
欢迎任何提示或解决方案。