Skip to content

Instantly share code, notes, and snippets.

@mitchellporter
Forked from chrishulbert/MyButton.m
Created December 5, 2015 09:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mitchellporter/fcddeb5718ef5207060e to your computer and use it in GitHub Desktop.
Save mitchellporter/fcddeb5718ef5207060e to your computer and use it in GitHub Desktop.
UIButton subclass
// How to subclass UIButton, given that it uses a static constructor so you can't override init.
@interface MyButton : UIButton
...
@end
@implementation MyButton
+ (instancetype)buttonWithType:(UIButtonType)buttonType {
MyButton *button = [super buttonWithType:buttonType];
[button postButtonWithTypeInit];
return button;
}
/// Because we can't override init on a uibutton, do init steps here.
- (void)postButtonWithTypeInit {
[self setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self setTitleColor:[UIColor grayColor] forState:UIControlStateHighlighted];
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment