Created
January 5, 2015 01:45
-
-
Save codetalks-new/4ccb4c7cf12533bec0e6 to your computer and use it in GitHub Desktop.
CircleImageView
This file contains 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 CircleImageView: UIImageView { | |
var borderWidth:CGFloat=6.0{ | |
didSet{ | |
updateBorderStyle() | |
} | |
} | |
var borderColor:UIColor=UIColor(white: 160, alpha: 0.5){ | |
didSet{ | |
updateBorderStyle() | |
} | |
} | |
override init(image: UIImage!) { | |
super.init(image: image) | |
commonInit() | |
} | |
override init(image: UIImage!, highlightedImage: UIImage?) { | |
super.init(image: image, highlightedImage: highlightedImage) | |
commonInit() | |
} | |
override init() { | |
super.init() | |
commonInit() | |
} | |
func commonInit(){ | |
println("commonInit") | |
layer.cornerRadius = frame.size.width * 0.5 | |
clipsToBounds = true | |
updateBorderStyle() | |
} | |
func updateBorderStyle(){ | |
layer.borderWidth = borderWidth | |
layer.borderColor = borderColor.CGColor | |
} | |
required init(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
commonInit() | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
commonInit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment