2012-12-06 15 views
0

我嘗試使用下面的代碼沒有任何的運氣定製中的UITabBar一樣定製中的UITabBar一樣:我嘗試使用下面的代碼沒有任何的運氣

這是我的viewDidLoad方法

UIImage *tabBackground = [[UIImage imageNamed:@"tabbar.png"] 
           resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)]; 
    // Set background for all UITabBars 
    [[UITabBar appearance] setBackgroundImage:tabBackground]; 
    // Set background for only this UITabBar 
    [[self.tabBarController tabBar] setBackgroundImage:tabBackground]; 

有什麼想法,我可能會在這裏出錯?謝謝

+0

你可以在你的代碼中加上這行'NSLog(@「%d」,tabBackground!= nil);'看看打印結果是'0'還是'1'?如果您看到「0」,則程序無法找到圖像。 – dasblinkenlight

+0

@dasblinkenlight控制檯輸出「1」 – hanumanDev

+0

我希望你已經看到這個鏈接http://felipecypriano.com/2012/02/27/how-to-customize-uitabbar-on-ios-5/ –

回答

1

我們可以改變UITabBar控制器的背景顏色。請參閱下面給出的代碼。希望這可以幫助你。

tabBar1.backgroundColor = [UIColor clearColor]; 
    CGRect frame = CGRectMake(0, 0, 480, 49); 
    UIView *view = [[UIView alloc] initWithFrame:frame]; 
    UIImage *image = [UIImage imageNamed:@"Image.png"]; 
    UIColor *color = [[UIColor alloc] initWithPatternImage:image]; 
    view.backgroundColor = color; 
    [color release]; 
    [[self tabBar] insertSubview:view atIndex:0]; 
    [view release]; 
相關問題