Last active
August 29, 2015 14:08
-
-
Save morizotter/5d3b0d251eff56072595 to your computer and use it in GitHub Desktop.
UIBezierPathで角丸にする ref: http://qiita.com/morizotter/items/8f5032e41339f1d82fa9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class RoundedCornersView: UIView { | |
override func drawRect(rect: CGRect) { | |
UIBezierPath(roundedRect: self.bounds, cornerRadius: CGRectGetHeight(self.bounds) / 2).addClip() | |
UIImage(named: "rocket")?.drawInRect(self.bounds) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class LayerRoundedCornersView: UIView { | |
override func drawRect(rect: CGRect) { | |
UIImage(named: "rocket")?.drawInRect(self.bounds) | |
let maskPath = UIBezierPath(roundedRect: self.bounds, cornerRadius: CGRectGetWidth(self.bounds) / 2) | |
let maskLayer = CAShapeLayer() | |
maskLayer.path = maskPath.CGPath | |
self.layer.mask = maskLayer; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment