我想製作一個自定義導航欄,就像在BestBuy App中一樣,或者像下面給出的屏幕截圖所示。如何創建自定義導航欄,如BestBuy App?
我想這種類型的導航是總是在每個頂部和每一個的viewController。
如果有人能告訴我的程序或任何形式的幫助,將不勝感激。謝謝。
我想製作一個自定義導航欄,就像在BestBuy App中一樣,或者像下面給出的屏幕截圖所示。如何創建自定義導航欄,如BestBuy App?
我想這種類型的導航是總是在每個頂部和每一個的viewController。
如果有人能告訴我的程序或任何形式的幫助,將不勝感激。謝謝。
編寫一個UINavigationBar的子類,在其中進行自定義繪圖並根據需要添加子視圖。
然後告訴你navigationController使用initWithNavigationBarClass:toolBarClass:
例如INITING它使用該類
@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;
}
如何告訴navigationController使用該類? –
看到編輯答案 –
那麼我將如何設置根控制器? –
的導航欄可以採取三種視圖,在每邊兩個按鈕左,右,你也可以添加爲標題的看法,,
//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;
是的,如果你不需要分隔符例如......雖然這些可能是在背景圖片..這對大多數情況下適用 –
肯定,但然後按鈕不會突出顯示觸摸,你的答案是更好的去。感謝, – Aziz
沒有看到.. –
,我不認爲他們使用的自定義導航欄......這是簡單的圖片:) – NSCry
他們可能不會。我同意。我的答案對此是過分的..它是最靈活的,但aziz的代碼看起來更適合這個我認爲。 ..雖然我不知道背景分離器 –