Skip to content

Instantly share code, notes, and snippets.

@osmszk
Created January 27, 2014 14:10
Show Gist options
  • Save osmszk/8649198 to your computer and use it in GitHub Desktop.
Save osmszk/8649198 to your computer and use it in GitHub Desktop.
button-tapped-osuzuki
- (void)viewDidLoad
{
UIButton *stateButton = [UIButton buttonWithType:UIButtonTypeCustom];
stateButton.exclusiveTouch = YES;
stateButton.frame = CGRectMake(10.0f, 180.0f, 300.0f, 46.0f);
stateButton.titleEdgeInsets = UIEdgeInsetsMake(0.0f, -300.0f, 0.0f, 0.0f);
stateButton.titleLabel.font = [UIFont boldSystemFontOfSize:17.0f];
[stateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[stateButton setImage:[UIImage imageNamed:@"alert_button_gray.png"] forState:UIControlStateNormal];
[stateButton setImage:[UIImage imageNamed:@"alert_button_blue.png"] forState:UIControlStateHighlighted];
[stateButton setImage:[UIImage imageNamed:@"alert_button_red.png"] forState:UIControlStateSelected];
[stateButton setImage:[UIImage imageNamed:@"alert_button_blue.png"] forState:UIControlStateSelected | UIControlStateHighlighted];
[stateButton setTitle:NSLocalizedString(@"Normal", nil) forState:UIControlStateNormal];
[stateButton setTitle:NSLocalizedString(@"Highlighted", nil) forState:UIControlStateHighlighted];
[stateButton setTitle:NSLocalizedString(@"Selected", nil) forState:UIControlStateSelected];
[stateButton setTitle:NSLocalizedString(@"Selected | Highlighted", nil) forState:UIControlStateSelected | UIControlStateHighlighted];
[stateButton addTarget:self action:@selector(tapped:) forControlEvents:UIControlEventTouchUpInside];
[contentView addSubview:stateButton];
}
- (void)tapped:(id)sender {
UIButton *button = (UIButton *)sender;
button.selected = !button.selected;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment