-
Notifications
You must be signed in to change notification settings - Fork 228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to center SVG layer? #138
Comments
Here is how I get the viewBox dynamically from the SVG @changelee82. It's probably not the most performant solution but it works for me. Thankfully the func viewBox(svgData: Data) -> CGRect? {
guard let string = String(data: svgData, encoding: .utf8),
let range = string.range(of: #" viewBox=\"([^"]+)\" "#, options: .regularExpression) else {
return nil
}
let matchParts = string[range].components(separatedBy: "\"")
guard matchParts.count == 3 else { return nil }
let viewBox = matchParts[1].components(separatedBy: " ").compactMap(Int.init)
guard viewBox.count == 4 else { return nil }
return .init(x: viewBox[0], y: viewBox[1], width: viewBox[2], height: viewBox[3])
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello! I create a UIImageView extension, but SVG layer is not center.
I found that the file contained viewBox="0 0 100 100", So I tried to add a line of code.
`
`
How to center other SVG layer?
I want to get the viewBox in svg file to setting boundingBox of svgLayer.
The text was updated successfully, but these errors were encountered: