簡體   English   中英

自定義TabBar顏色iOS 5.0.1

[英]Custom TabBar colour iOS 5.0.1

我想使用自定義TabBar顏色。

Afetr iOS 5發行版中,我使用了以下代碼:

CGRect frame = CGRectMake(0, 0, 480, 49);
UIView *view = [[UIView alloc] initWithFrame:frame];
UIImage *tabBarBG = [UIImage imageNamed:@"tabBar.png"];
UIColor *color = [[UIColor alloc] initWithPatternImage:tabBarBG];
[view setBackgroundColor:color];
[color release];

if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {

[self.tabBarController.tabBar insertSubview:view atIndex:1];
}
else {

[self.tabBarController.tabBar insertSubview:view atIndex:0];
}

[view release];

在iOS 5中可以,但在iOS 5.0.1中則無法使用。

如何在iOS 5.0.1中設置TabBar顏色?

謝謝

由於新的外觀API,您在iOS5中不再需要該技巧。 您可以在iOS 5的標簽欄上設置諸如backgroundImage和tintColor之類的屬性,因此只需執行以下操作:

if ([self.tabBarController.tabBar respondsToSelect:@selector(setBackgroundImage:)])
{
    self.tabBarController.tabBar.backgroundImage = someImage;
}
else
{
    //use the old iOS4 subview hack
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM