1

What I'm trying to achieve is to have middle tab image stretched on different resolutions (i5, i6, i6+...), there are 5 tabs so middle one is always 1/5 of screen width.

This code is not stretching on full width of middle tab:

UITabBarItem *timelineTabBarItem = [[UITabBarItem alloc] initWithTitle:@"Middle"
                                                                 image:[[[UIImage imageNamed:@"tab3-on"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 31, 0, 32)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
                                                         selectedImage:[[[UIImage imageNamed:@"tab3-off"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 31, 0, 32)] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
timelineViewController.tabBarItem = timelineTabBarItem;

On i6+ I see image in center of tab.

What I'm missing / how to fill tab image correctly?

Update:

Here is preview image: https://i.stack.imgur.com/H1xUD.png

Green is original image that should cover dark blue area.

gvuksic
  • 2,983
  • 3
  • 32
  • 37

1 Answers1

0

Try This,

UIImageView imgBgView =  [[UIImageView alloc] initWithFrame:CGRectMake(itemWidth*itemIndex,0,itemWidth,self.tabBarViewController.tabBar.frame.size.height)];
imgBgView.image = [[UIImage imageNamed:@"tab_icon_checkin_inactive.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:0];
imgBgView.contentMode = UIViewContentModeScaleAspectFit;
[self.tabBar.tabBar insertSubview:imgBgView atIndex:0];

Here itemWidth is the width of one tab to get it use,

float itemWidth = [[UIScreen mainScreen] bounds].size.width / (float)(self.tabBarViewController.tabBar.items.count);

it will set the image at the middle tab in tabbar.

Hope it will Help You.

JigneshP
  • 344
  • 2
  • 7