[英]Could not set Image on Navigation bar only in “ios 5.0”
在我的通用應用中
我正在導航欄上設置圖像...使用**
objective c category...on UINavigationBar
**
該代碼在iPhone的ios 5.0中 可以正常工作 * 該代碼在iPhone / iPad的ios 4.3中可以正常工作 *
*But not working in **ios 5.0 iPad***
- (void) drawRect:(CGRect)rect
{
UIImage *image;
image = [UIImage imageNamed: @"Navigation.png"];
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
[self setTintColor:[UIColor clearColor]];
NSLog(@"Draw Rect");
}
要在iOS 5中為導航欄設置BG圖片,您可以使用以下代碼
if ([self.navigationController.navigationBar respondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"Navigation.png"] forBarMetrics:UIBarMetricsDefault];
}
但是請記住,這在iOS 4中不起作用。要使其在兩種環境中都起作用,還需要向UINavigationBar添加類別。
@implementation UINavigationBar (UINavigationBarCategory)
- (void)drawRect:(CGRect)rect {
UIImage *img = [UIImage imageNamed:@"Navigation.png"];
[img drawInRect:rect];
}
如果要在整個應用程序范圍內設置后台,則可以使用iOS5的UIAppearance。
[[UINavigationBar appearance] setBackgroundImage:X forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:X forBarMetrics:UIBarMetricsLandscape];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.