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