Permalink
Browse files

Fixed issue with ignored target/action on create with Target/Action

  • Loading branch information...
1 parent 8a995ca commit c4877412ccb5a10d5f7a9d547e23e4cbe4d1ce97 @mikeho committed Oct 7, 2011
Showing with 16 additions and 4 deletions.
  1. +16 −4 QSBarButtonItems.m
View
@@ -43,10 +43,22 @@ + (UIBarButtonItem *)createToolbarButtonWithText:(NSString *)strText {
}
+(UIBarButtonItem *)createToolbarButtonWithText:(NSString *)strText target:(id)objTarget action:(SEL)objSelector {
- UIBarButtonItem * btnToReturn = [self createToolbarButtonWithText:strText];
- [btnToReturn setTarget:objTarget];
- [btnToReturn setAction:objSelector];
- return btnToReturn;
+ CGSize objSize = [strText sizeWithFont:[UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]];
+ UILabel * lblTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, objSize.width, objSize.height)];
+ [lblTitle setFont:[UIFont boldSystemFontOfSize:[UIFont smallSystemFontSize]]];
+ [lblTitle setTextColor:[UIColor whiteColor]];
+ [lblTitle setBackgroundColor:[UIColor clearColor]];
+
+ [lblTitle setText:strText];
+
+ UIButton * btnTitle = [UIButton buttonWithType:UIButtonTypeCustom];
+ [btnTitle setFrame:[lblTitle frame]];
+ [btnTitle addSubview:lblTitle];
+ [lblTitle release];
+ [btnTitle addTarget:objTarget action:objSelector forControlEvents:UIControlEventTouchUpInside];
+
+ UIBarButtonItem * btnToReturn = [[UIBarButtonItem alloc] initWithCustomView:btnTitle];
+ return [btnToReturn autorelease];
}
@end

0 comments on commit c487741

Please sign in to comment.