我正在使用PocketSVG
将我的SVG
文件转换为CGPath
,就像这样:
override func awakeFromNib() {
super.awakeFromNib()
let myPath = PocketSVG.pathFromSVGFileNamed("CategoriesBar").takeUnretainedValue()
let lineWidth: CGFloat = 3.0
let insetRect = CGRectInset(bounds, lineWidth / 2.0, lineWidth / 2.0)
let boundingRect = CGPathGetPathBoundingBox(myPath)
let scale = insetRect.size.width / boundingRect.size.width
var transform = CGAffineTransformScale(CGAffineTransformMakeTranslation(-boundingRect.origin.x * scale + insetRect.origin.x, -boundingRect.origin.y * scale + insetRect.origin.y), scale, scale)
let transformedPath = CGPathCreateMutableCopyByTransformingPath(myPath, &transform)
let myShapeLayer = CAShapeLayer()
myShapeLayer.path = transformedPath
myShapeLayer.strokeColor = UIColor.redColor().CGColor
myShapeLayer.lineWidth = lineWidth
myShapeLayer.fillColor = UIColor.whiteColor().CGColor
self.layer.addSublayer(myShapeLayer)
}
问题是myShapeLayer
视野越大,它被切断了,我希望路径的宽度(我不关心高度)等于查看宽度。
我该怎么做?
谢谢!