UITabBar Custom Color Icons

I am trying to implement custom colors in a UITabBar. But I do not know what the problem is. I placed the image on 1 tabBar.when tabBar is active, I want one image and when tabBar is inactive, I want another image to be displayed on the same tabBar. How? Also tell me that the image is placed in the center of the tabBar. Please tell me the Xcode for this implementation - (void) viewWillAppear: (BOOL) animated {
  [super viewWillAppear: animated];
  for (UIView * view in self.tabBarController.tabBar.subviews) {
      if ([view isKindOfClass: [UIImageView class]]) {
          [view removeFromSuperview];
      }
  }

[self.tabBarController.tabBar insertSubview:[[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Icon-a.png"]] autorelease] atIndex:0];  

}

  • (void) viewWillDisappear: (BOOL) animated {// [superviewWillDisappear: animated]; for (UIView * view in self.tabBarController.tabBar.subviews) {
      if ([view isKindOfClass: [UIImageView class]]) {
          [view removeFromSuperview];
      }
    }

    [self.tabBarController.tabBar insertSubview: [[[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "Icon-c.png"]] autorelease] atIndex: 0];
    }
    I used these methods to accomplish my task. But I canโ€™t get a solution. Please help me

+3
source share

Source: https://habr.com/ru/post/1777671/


All Articles