2013-02-07 16 views
6

मैं एक कस्टम नेविगेशन बार बनाना चाहता हूं जैसे कि BestBuy ऐप में या नीचे दिए गए स्क्रीनशॉट में दिखाया गया है।बेस्टब्यू ऐप जैसे कस्टम नेविगेशन बार कैसे बनाएं?

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

उस कक्षा का उपयोग करने के लिए नेविगेशन नियंत्रक को कैसे बताना है? –

+0

संपादित उत्तर –

+0

देखें फिर मैं रूट नियंत्रक कैसे सेट करूं? –

4

navigationBar प्रत्येक पक्ष में दो बटन छोड़ दिया और सही तीन देखने के लिए, ले जा सकते हैं, यह भी आप जोड़ सकते हैं शीर्षक के लिए एक दृश्य,

//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

धन्यवाद, यह नहीं देखा .. –

संबंधित मुद्दे