Я создаю один UIToolbar с кодом, а другой - с построителем интерфейса. Но выяснилось, что две панели инструментов имеют различную левую и правую прокладку, которые показаны ниже:
Из интерфейса Builder:
Из кода:
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];
Мой вопрос в том, как я могу настроить левое и правое заполнение UIToolbar кодом?
Обновление
Я обнаружил, что эта проблема выравнивания происходит только с UIBarButtonItem с customView UIButton, выравнивание в порядке с UIBarButtonItem. Любая идея, что вызывает это или разрешает это.
Единственное решение, о котором я могу сейчас подумать, - это вручную установить фрейм.