Skip to content

Instantly share code, notes, and snippets.

@chrishulbert
Created May 30, 2011 04:48
Show Gist options
  • Save chrishulbert/998464 to your computer and use it in GitHub Desktop.
Save chrishulbert/998464 to your computer and use it in GitHub Desktop.
Putting a UIButton on a UIToolbar
UIButton *myBn = [UIButton buttonWithType:UIButtonTypeCustom];
[myBn setTitle:@"Blah" forState:UIControlStateNormal];
myBn.frame = CGRectMake(0, 0, 100, 44);
[myBn addTarget:self action:@selector(myBnWasClicked:) forControlEvents:UIControlEventTouchUpInside];
myBn.titleLabel.font = [UIFont fontWithName:@"Some Font" size:16];
[myBn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
myBn.showsTouchWhenHighlighted = YES;
UIBarButtonItem *myBbi = [[[UIBarButtonItem alloc] initWithCustomView:sortCustomButton] autorelease];
self.myToolbar.items = [NSMutableArray arrayWithObjects:myBbi, nil];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment