自定义UITabBarController的tabBar背景图片

来源:互联网 发布:log4j 性能优化 编辑:程序博客网 时间:2024/06/06 01:25

新建一个类继承UITabBarController:

 

- (id) init

{

    self = [super init];

    if (self) {

        //方法一

        UIImageView *img = [[UIImageView allocinitWithImage:[UIImage imageNamed:@"bg.png"]];

        img.frame = CGRectMake(00self.tabBar.frame.size.widthself.tabBar.frame.size.height);

        img.contentMode = UIViewContentModeScaleToFill;

        //img.frame = CGRectOffset(img.frame, 0, 1);

        [[self tabBarinsertSubview:img atIndex:0];

        [img release];

 

        //方法二

        CGRect frame = CGRectMake(00self.view.bounds.size.width49);

        UIView *view = [[UIView allocinitWithFrame:frame];

        UIImage *tabBarBackgroundImage = [UIImage imageNamed:@"bg.png"];

        UIColor *color = [[UIColor allocinitWithPatternImage:tabBarBackgroundImage];

        [view setBackgroundColor:color];

        [color release];

        [[self tabBarinsertSubview:view atIndex:0];

        [view release];

    }

    return self;

}