彪哥的方法

来源:互联网 发布:益邦控股集团 知乎 编辑:程序博客网 时间:2024/04/29 07:11

新建一个类继承UITabBarController:


- (id) init

{

    self = [super init];

    if (self) {

        //方法一

        UIImageView *img = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"bg.png"]];

        img.frame = CGRectMake(0,0, self.tabBar.frame.size.width,self.tabBar.frame.size.height);

        img.contentMode =UIViewContentModeScaleToFill;

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

        [[selftabBar] insertSubview:img atIndex:0];

        [img release];

        

        //方法二

        CGRect frame = CGRectMake(0,0, self.view.bounds.size.width,49);

        UIView *view = [[UIViewalloc] initWithFrame:frame];

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

        UIColor *color = [[UIColoralloc] initWithPatternImage:tabBarBackgroundImage];

        [view setBackgroundColor:color];

        [color release];

        [[selftabBar] insertSubview:view atIndex:0];

        [view release];

    }

    return self;

}

原创粉丝点击