Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
UI_APPEARANCE_SELECTOR in Swift
class CBArticleCellStarView: UIView {
var star: UIImageView = UIImageView(image: UIImage(named: "ArticleUnstarred"))
var starred: Bool = false {
didSet {
self.star.image = self.starred ? UIImage(named: "ArticleStarred") : UIImage(named: "ArticleUnstarred")
}
}
override init(frame: CGRect) {
super.init(frame: frame)
self.setup()
}
required init(coder: NSCoder) {
super.init(coder: coder)
self.setup()
}
func setup() {
self.setStarViewColor(UIColor.redColor())
self.star.center = CGPoint(x: CGRectGetWidth(self.bounds)/2, y: CGRectGetHeight(self.bounds)/2)
self.star.autoresizingMask = .FlexibleLeftMargin | .FlexibleRightMargin | .FlexibleTopMargin | .FlexibleBottomMargin
self.addSubview(self.star)
}
// Appearance property accessor method
func setStarViewColor(color: UIColor) {
self.backgroundColor = color
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment