2013-05-01 164 views
1

我試着用圖片爲我的導航欄的背景,但不能讓它到達邊緣:UINavBar拉伸圖像邊緣

enter image description here

我給自己定的圖像尺寸爲320 X 44和640×88

這是代碼來設置它吧:

self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navBar.png"]]; 

回答

3

這將適用於整個應用程序。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    UINavigationBar *navigationBar = [UINavigationBar appearance]; 
    UIImage *image = [UIImage imageNamed:@"navBar.png"]; 
    [navigationBar setBackgroundImage:image forBarMetrics:UIBarMetricsDefault]; 
} 
+0

很棒 - 謝謝! – Robert 2013-05-01 20:59:08

+0

@Robert記得標記他的答案是正確的,如果它幫助你 – Undo 2013-05-01 21:02:18

+0

我會盡快讓你的答案允許。 – Robert 2013-05-01 21:04:36

1

使用此

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navBar.png" forBarMetrics:UIBarMetricsDefault]; 

希望它可以幫助你。

+0

它的確如此,謝謝。結果Viktor的答案效果最好,但你的答案也很好,所以得到了讚揚。 – Robert 2013-05-01 21:05:39