更改标签栏可能会导致您在应用审核时遇到问题。
为了更容易自定义,请尝试使用自定义标签栏控件。
查看Here 以获得可轻松完全自定义的标签栏组件的优秀开源列表。
告诉我这是否解决了您的问题,否则我们可以进行进一步的定制。
编辑:
嗯,这是你需要做的:
1-为背景创建一个圆形透明png:
2- 创建一个自定义的 uitabbarController 类并将该代码放入 ViewDidLoad:
[[UITabBar appearance] setBarTintColor:[UIColor clearColor]];
self.tabBarController.tabBar.translucent = YES;
UIImage *image = [self imageWithImage:[UIImage imageNamed:@"circle.png"]scaledToSize:CGSizeMake(self.tabBar.frame.size.height+1, self.tabBar.frame.size.height+1)];
UIEdgeInsets edgeInsets;
edgeInsets.left = image.size.width/2;
edgeInsets.top = 0.0f;
edgeInsets.right = image.size.width/2; //this will be the constant portion in your image
edgeInsets.bottom = 0.0f;
image = [image resizableImageWithCapInsets:edgeInsets];
[[UITabBar appearance] setBackgroundImage:image];
使用此方法调整图像大小以适合 UITabBar 高度:
- (UIImage *)imageWithImage:(UIImage *)image scaledToSize:(CGSize)newSize {
//UIGraphicsBeginImageContext(newSize);
// In next line, pass 0.0 to use the current device's pixel scaling factor (and thus account for Retina resolution).
// Pass 1.0 to force exact pixel size.
UIGraphicsBeginImageContextWithOptions(newSize, NO, 0.0);
[image drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
结果如下:
如果还不清楚,我给你做了一个xcode项目并上传到github,请随意使用它来满足你的需要:)
Custom UITabBarController by Sdiri Houssem on Github
最好的问候