KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I create one UIToolbar with code and another with interface builder. But, found out the two toolbar having different left and right padding which shown below: From Interface Builder: From Code: UIImage *buttonImage = [[UIImage imageNamed:@"button.png"] stretchableImageWithLeftCapWidth:10 topCapHeight:0]; UIButton *btnTest = [UIButton buttonWithType:UIButtonTypeCustom]; [btnTest setBackgroundImage:buttonImage forState:UIControlStateNormal]; [btnTest setTitle:@"Back" forState:UIControlStateNormal]; [btnTest.titleLabel setFont:[UIFont boldSystemFontOfSize:13]]; [btnTest setBackgroundImage:[imgToolbarButton stretchableImageWithLeftCapWidth:5 topCapHeight:0] forState:UIControlStateNormal]; [btnTest addTarget:self action:@selector(clearDateEdit:) forControlEvents:UIControlEventTouchUpInside]; btnTest.frame = CGRectMake(0.0, 0.0, 50, 30); UIBarButtonItem *btnTestItem = [[UIBarButtonItem alloc] initWithCustomView:btnTest]; [self.toolbar setItems:[NSArray arrayWithObjects:btnTestItem,nil]]; [btnTestItem release]; My question is how can I adjust the left and right padding of UIToolbar by code? Update I discovered this alignment issue only happen to UIBarButtonItem with customView of UIButton, the alignment is fine with UIBarButtonItem. Any idea what cause this or to resolve this. The only solution I can think of right now is to manually set the frame.
Tags (comma-separated)
Save Edits
Cancel