1. 程式人生 > >自定義UITabBarController的tabBar背景圖片

自定義UITabBarController的tabBar背景圖片

新建一個類繼承UITabBarController:

- (id) init

{

    self = [super init];

    if (self) {

        //方法一

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

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

        img.contentMode

 = UIViewContentModeScaleToFill;

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

        [[selftabBarinsertSubview: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];

        [[selftabBarinsertSubview:view atIndex:0];

        [view release];

    }

returnself;

}