1.UITabBarController更换tabBar背景图片
UITabBarController* tabBarController = [[UITabBarController alloc] init];
NSArray *array = [tabBarController.view subviews];
UITabBar *tabBar = [array objectAtIndex:1];
UIImage *image = [UIImage imageWithContentsOfFile:sourcePath ];
tabBar.layer.contents = (id)image.CGImage;
2. UINavigationBar 更换tabBar背景图片
@interface UINavigationBar (MyCustomNavBar)
@end
@implementation UINavigationBar (MyCustomNavBar)
- (void) drawRect:(CGRect)rect {
UIImage *barImage = [UIImage imageNamed:@"title_part.png"];
[barImage drawInRect:rect];
}
@end
本文介绍如何为UITabBarController的tabBar及UINavigationBar设置自定义背景图片。对于UITabBarController, 通过获取其view的子视图并设置UITabBar的layer.contents属性来实现;对于UINavigationBar, 则是通过扩展类别并在drawRect方法中绘制背景图片。
892

被折叠的 条评论
为什么被折叠?



