Skip to content

Instantly share code, notes, and snippets.

@guojiubo
Created December 4, 2014 02:24
Show Gist options
  • Save guojiubo/adff619fdba8f8ba698c to your computer and use it in GitHub Desktop.
Save guojiubo/adff619fdba8f8ba698c to your computer and use it in GitHub Desktop.
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