Skip to content

Instantly share code, notes, and snippets.

@morizotter
Last active August 29, 2015 14:08
Show Gist options
  • Save morizotter/5d3b0d251eff56072595 to your computer and use it in GitHub Desktop.
Save morizotter/5d3b0d251eff56072595 to your computer and use it in GitHub Desktop.
UIBezierPathで角丸にする ref: http://qiita.com/morizotter/items/8f5032e41339f1d82fa9
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)
}
}
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