Reputation: 2983
I created a TabBar for all iphone but in iphone 5 showing properly but in iphone 6 not showing properly image iPhone 6 showing like that i want proper spacing between tabbaritem and left and right
in Iphone 5 showing properly
I am using this code
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UITabBar *tabBar = self.tabBar;
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"footer_bg"]];
[[UITabBar appearance] setTintColor:[UIColor clearColor]];
[[UITabBar appearance] setTintColor:[UIColor clearColor]];
self.delegate=self;
self.imgTab1= getImgViewForTab(CGRectMake(0, 6, 80, 39), @"listings_active.png");
self.imgTab1.autoresizesSubviews = YES;
self.imgTab1.autoresizingMask = LEFT_MARGIN & TOP_MARGIN & BOTTOM_MARGIN & F_WIDTH & F_HEIGHT;
[tabBar addSubview:self.imgTab1];
self.imgTab2= getImgViewForTab(CGRectMake(80, 6, 80, 39), @"bids.png");
self.imgTab2.autoresizesSubviews = YES;
self.imgTab2.autoresizingMask = TOP_MARGIN & BOTTOM_MARGIN & F_WIDTH & F_HEIGHT;
[tabBar addSubview:self.imgTab2];
self.imgTab3= getImgViewForTab(CGRectMake(160, 6, 80, 39), @"reservations.png");
self.imgTab3.autoresizesSubviews = YES;
self.imgTab3.autoresizingMask = TOP_MARGIN & BOTTOM_MARGIN & F_WIDTH & F_HEIGHT;
[tabBar addSubview:self.imgTab3];
self.imgTab4= getImgViewForTab(CGRectMake(240, 6, 80, 39), @"settings.png");
self.imgTab4.autoresizesSubviews = YES;
self.imgTab4.autoresizingMask = RIGHT_MARGIN & TOP_MARGIN & BOTTOM_MARGIN & F_WIDTH & F_HEIGHT;
[tabBar addSubview:self.imgTab4];
[self setSelectedTabImage:tabbarindexG];
}
Upvotes: 0
Views: 657
Reputation: 14128
It seems to me as a wrong approach to assign image to tabbar item. Please refer this code;
You have to specify the images for every tab item. The following code is working for me
if ([[tabBarController.tabBar.items objectAtIndex:0] respondsToSelector:@selector(setFinishedSelectedImage:withFinishedUnselectedImage:)]) {
[[tabBarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"simg1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"img1.png"]];
[[tabBarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"simg2.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"img2.png"]];
// Do the same if there are more tabs
}
Or use default setImage
and setSelectedImage
accessor methods:
// both at once
[initWithTitle:image:selectedImage:][1]
// only setImage
[[tabBarController.tabBar.items objectAtIndex:0] setImage: [UIImage imageNamed: @"tab_1_image"]];
// only setSelectedImage
[[tabBarController.tabBar.items objectAtIndex:0] setSelectedImage: [UIImage imageNamed: @"tab_1_selected_image"]];
iOS API will automatically adjust frame and placement for image, there is no need to assign frame for image.
Hope this will solve your problem.
Upvotes: 4