Здравствуйте, я пытался выяснить, как изменить «заполнение», которое, как мне кажется, является цветом оттенка для UIBarButtonItem, но когда я пытаюсь это сделать, используя внешний вид или внешний видWhenContainedIn не работает держать давая мне икону синий:UIBarButtonItem изменить значок заливки на белый ios
Я хочу это может быть белым, когда я настроить кнопку сама я в состоянии изменить оттенок цвета, и это работает, но я хотел бы сделайте это с внешним видом для всех моих кнопок. Вот код, в котором я делаю стилизацию. Если кто-то может дать мне подсказку или подсказку, как это сделать?
-(void)applyStyle {
[self styleUIButtons];
UIImage *navigationBarBackground = [[UIImage imageNamed:@"base_nav_bar" ] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
[[UINavigationBar appearance]setBackgroundImage:navigationBarBackground forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName: self.mainNavigationBarTextColor}];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName: self.mainNavigationBarTextColor} forState:UIControlStateNormal];
[[UIButton appearanceWhenContainedIn:[UINavigationBar class], nil] setTitleColor:self.mainNavigationBarTextColor forState:UIControlStateNormal];
UIImage* barButtonImage = [self createSolidColorImageWithColor:[UIColor colorWithWhite:1.0 alpha:0.1] andSize:CGSizeMake(10, 10)];
[[UIBarButtonItem appearance] setBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIButton appearanceWhenContainedIn:[UINavigationBar class], nil] setBackgroundImage:barButtonImage forState:UIControlStateNormal];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setTintColor:self.mainNavigationBarIconColor ];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont boldSystemFontOfSize:12], NSFontAttributeName,
[UIColor grayColor], NSForegroundColorAttributeName,
nil];
[[UISegmentedControl appearance]setTitleTextAttributes:attributes forState:UIControlStateNormal];
}
-(UIImage*)createSolidColorImageWithColor:(UIColor*)color andSize:(CGSize)size{
CGFloat scale = [[UIScreen mainScreen] scale];
UIGraphicsBeginImageContextWithOptions(size, NO, scale);
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGRect fillRect = CGRectMake(0,0,size.width,size.height);
CGContextSetFillColorWithColor(currentContext, color.CGColor);
CGContextFillRect(currentContext, fillRect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
- (void) styleUIButtons {
UIImage *buttonNormalBg = [[UIImage imageNamed:@"button_normal" ] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
UIImage *buttonSelectedBgb = [[UIImage imageNamed:@"button_selected" ] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
id appearance = [UIButton appearance];
[appearance setTintColor:self.mainNavigationBarTextColor];
[appearance setBackgroundImage:buttonNormalBg forState:UIControlStateNormal];
[appearance setBackgroundImage:buttonSelectedBgb forState:UIControlStateHighlighted];
}
Когда вы говорите, что вы хотите быть белыми , вы имеете в виду иконку дерева в барбутке? – bizsytes
Да, ну, на самом деле это белый, но барбатон поставил его в синий цвет. – Necronet
Взгляните на видеоролик «Настройка вашего приложения для iOS 7» от WWDC 2013. Я не знаю точного ответа на ваш вопрос, но это видео довольно много говорит о навигационных панелях, UIToolbars, UITabBars и UIColor. – bizsytes