Настройка внешнего вида только одного UIToolbar в iOS 8

У меня есть две панели инструментов, расположенные друг над другом. Они создаются программно. Нижняя панель использует стандартные элементы UIButton с однотонным фоном, а кнопки наследуют оттенок.

Однако я хочу, чтобы панель инструментов над ней имела фоновое изображение. Я могу заставить это работать только с помощью средства настройки внешнего вида, однако свойство внешнего вида применяется к обеим панелям инструментов. Может ли кто-нибудь увидеть способ обойти это?

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

///top toolbar///



UIToolbar *toolbar2 = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.bounds.size.height-84, self.view.bounds.size.width, 44)];
toolbar2.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
[self.view addSubview:toolbar2];
UIImage *testimage = [[UIImage imageNamed:@"test.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsLandscapePhone];


///////bottom toolbar////


UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0,    self.view.bounds.size.height-44, self.view.bounds.size.width, 44)];
toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
toolbar.barTintColor=[UIColor colorWithHexValue:0xff336600];
[self.view addSubview:toolbar];

UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"help.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openHelpView)];
button1.tintColor=[UIColor whiteColor];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
UIBarButtonItem *button2=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"web.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openWebView)];
 button2.tintColor=[UIColor whiteColor];
UIBarButtonItem *button3 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"fb-icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openFBView)];
button3.tintColor=[UIColor whiteColor];
UIBarButtonItem *button4 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"twitter.png"] style:UIBarButtonItemStylePlain target:self action:@selector(openTwitterView)];
button4.tintColor=[UIColor whiteColor];

[toolbar setItems:[[NSArray alloc] initWithObjects:button1,spacer,button3,spacer,button4,spacer,button2, nil]];
[self.view addSubview:toolbar];

person PocketTim    schedule 07.04.2015    source источник


Ответы (1)


Догадаться.

Просто создал пустой подкласс класса UIToolbar, а затем вместо этого создал мою верхнюю панель инструментов. Таким образом, я могу применить свойство внешнего вида отдельно.

person PocketTim    schedule 07.04.2015