Skip to content

Commit

Permalink
Fix vertical alignment of icon in UIImage, prove in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
tomsterritt committed Feb 26, 2016
1 parent be568ea commit 70f94cb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Example-ionicons/Example-ionicons/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ class ViewController: UIViewController {
// Image example
let imageView = UIImageView(frame: CGRectMake(10, 100, 50, 50))
imageView.image = UIImage.imageWithIonicon(ionicon.Wand, color: UIColor.greenColor(), iconSize: 40.0, imageSize: CGSizeMake(50, 50))

// Border to prove central
imageView.layer.borderWidth = 1
imageView.layer.borderColor = UIColor.redColor().CGColor

self.view.addSubview(imageView)
}

Expand Down
2 changes: 1 addition & 1 deletion ionicons/ionicons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public extension UIImage {

let boundingRect = attString.boundingRectWithSize(CGSize(width: iconSize, height: iconSize), options: .UsesDeviceMetrics, context: ctx)

attString.drawInRect(CGRect(x: (imageSize.width / 2) - boundingRect.size.width / 2, y: (imageSize.height / 2) - boundingRect.size.height / 2, width: imageSize.width, height: imageSize.height))
attString.drawInRect(CGRect(x: (imageSize.width / 2) - (boundingRect.size.width / 2), y: (imageSize.height / 2) - (iconSize / 2), width: imageSize.width, height: imageSize.height))

var image = UIGraphicsGetImageFromCurrentImageContext()

Expand Down

0 comments on commit 70f94cb

Please sign in to comment.