I am using a UITabBarController in my application (for iPhone 5). When i am trying to set an image on the TabBAr, the image shows a line. I have seen two questions similar to mine, but did not understand the solution.
Here's how I am adding the image:
UIImageView *tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubview:tabBarView];
The dimensions of my current image is 320X64 pixels. How to resolve this issue??
write this in appdelegate.m didfinishLanching method
UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_select_indicator"]];
In iOS 6 and aboove the UITabBar has a shadow image, if you want to disable it you can just call yourTabBar.shadowImage = [UIImage new]
.
In your case tabBarController.tabBar.shadowImage = [UIImage new]
Yes, it is possible to make it exact size.
Use this code if you are just using a UITabBar
inside your view:
Type :1
UITabBar *tabBar = [[UITabBar alloc]initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 60)];
[self.view addSubview:tabBar];
UIImageView *tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBar.png"]];
tabBar.backgroundImage = tabBarView.image;
Presently my image size is 320 x 5
Type 2:
If you are using a UITabBarController
then use it like this
UIImageView *tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBar.png"]];
UITabBarController *tabController = [[UITabBarController alloc]init];
tabController.tabBar.backgroundImage = tabBarView.image;
Here are the screen shot for both.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.