2013-02-07 6 views
6

BestBuy Appのようなカスタムナビゲーションバーを作成したい場合は、下記のスクリーンショットを参照してください。BestBuy Appのようなカスタムナビゲーションバーを作成するには?

enter image description here

私はナビゲーションのこのタイプは、一人ひとりのViewControllerの上に常になりたいです。

誰かが手続きやあらゆる種類の助けを受けていただければ幸いです。ありがとう。

+0

を追加するために、私はそれは、単純なイメージだ...彼らはカスタムナビゲーションバーを使用しているとは思わない:) – NSCry

+0

彼らはそう..私は同意しません。私の答えはこれのために残忍です..それは最も柔軟ですが、私は思うが、アジズのコードはよりよく見えます。 ..私はバックグラウンド区切りについてはわかりませんが –

答えて

11

カスタム図面を作成し、必要に応じてサブビューを追加するUINavigationBarのサブクラスを作成します。その後、

initWithNavigationBarClass:toolBarClass:

例えばを使用してそれをINITINGことで、そのクラスを使用するようにnavigationControllerを伝えます代わりの

@interface MyBar : UINavigationBar 
@end 

@implementation MyBar 
.... //like any UIView 
@end 

UINavigationController *navi = [[UINavigationController alloc] initWithNavigationBarClass:[MyBar class] toolbarClass:nil]; 

initWithRootViewController


サンプル

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
// Override point for customization after application launch. 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
    self.mainViewController = [[FDMainViewController alloc] initWithNibName:@"FDMainViewController_iPhone" bundle:nil]; 
} else { 
    self.mainViewController = [[FDMainViewController alloc] initWithNibName:@"FDMainViewController_iPad" bundle:nil]; 
} 

UINavigationController *navi = [[UINavigationController alloc] initWithNavigationBarClass:[UINavigationBar class] toolbarClass:nil]; 
navi.viewControllers = @[self.mainViewController]; 
self.window.rootViewController = navi; 
[self.window makeKeyAndVisible]; 
return YES; 
} 
+0

navigationControllerにそのクラスを使用する方法を教えてください。 –

+0

編集された回答を参照 –

+0

次にルートコントローラをどのように設定しますか? –

4

navigationBarは3つのビュー、それぞれの側に2つのボタンは、左と右を取ることができ、また、あなたが追加することができますタイトルのビュー、

//this will set a background image to your navigation bar. 
[[self.navigationController navigationBar] setBackgroundImage:[UIImage imageNamed:@"top-bar.png"] forBarMetrics:UIBarMetricsDefault]; 

UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[leftButton setBackgroundImage:[UIImage imageNamed:@"backBtn.png"] forState:UIControlStateNormal]; 
leftButton.frame = CGRectMake(0, 0, 66, 30); 
[leftButton addTarget:self action:@selector(navBack) forControlEvents:UIControlEventTouchUpInside]; 
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton]; 

UIImage *image=[UIImage imageNamed:@"add-btn.png"]; 
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
button.bounds = CGRectMake(0, 0, image.size.width, image.size.height); 
[button setBackgroundImage:image forState:UIControlStateNormal]; 
[button addTarget:self action:@selector(doneAct) forControlEvents:UIControlEventTouchUpInside]; 
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 

と検索バー

self.navigationItem.titleView = mySearchbarView; 
+0

はい、セパレータは必要ないたとえば、それらは背景画像にある可能性がありますが、これはほとんどの場合 –

+0

で動作しますが、ボタンがタッチされても強調表示されない場合は、回答が得策です。 – Aziz

+0

ありがとう、それを見ていない.. –

関連する問題