Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to adjust UIToolBar left and right padding
    primarykey
    data
    text
    <p>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:</p> <p>From Interface Builder:</p> <p><img src="https://i.stack.imgur.com/sthpU.png" alt="enter image description here"></p> <p>From Code:</p> <p><img src="https://i.stack.imgur.com/gaN9u.png" alt="enter image description here"></p> <pre><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]; </code></pre> <p>My question is how can I adjust the left and right padding of UIToolbar by code?</p> <p><strong>Update</strong></p> <p>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.</p> <p>The only solution I can think of right now is to manually set the frame.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload