8

मैं UINavigationBar (कस्टम पृष्ठभूमि छवि & टेक्स्ट रंग सेट करने के लिए) को उपclass करना चाहता था और मेरे ऐप में सभी नेविगेशन बार के लिए इसका उपयोग करना चाहता था। UINavigationController के लिए एपीआई डॉक्स को देखते हुए, यह लग रहा है navigationBar की तरह केवल पढ़ने के लिए है:उपनिवेश UINavigationBar ... मैं इसे UINavigationController में कैसे उपयोग करूं?

@property (nonatomic, रीड-ओनली) UINavigationBar * navigationBar

वहाँ एक रास्ता वास्तव में एक कस्टम UINavigationBar उपयोग करने के लिए है मेरे UIViewControllers? मुझे पता है कि अन्य एप्लिकेशन कस्टम नेविगेशन सलाखों किया है, फ़्लिकर की तरह:

#import <UIKit/UIKit.h> 

@interface MyNavigationBar : UINavigationBar <UINavigationBarDelegate> { 

} 

@end 

कार्यान्वयन

#import "MyNavigationBar.h" 

@implementation MyNavigationBar 

- (id)initWithFrame:(CGRect)frame { 
    if (self = [super initWithFrame:frame]) { 
     // Initialization code 
    } 
    return self; 
} 

- (void)drawRect:(CGRect)rect { 
    // override the standard background with our own custom one 
    UIImage *image = [[UIImage imageNamed:@"navigation_bar_bgd.png"] retain]; 
    [image drawInRect:rect]; 
    [image release]; 
} 

#pragma mark - 
#pragma mark UINavigationDelegate Methods 

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 
    // use the title of the passed in view controller 
    NSString *title = [viewController title]; 

    // create our own UILabel with custom color, text, etc 
    UILabel *titleView = [[UILabel alloc] init]; 
    [titleView setFont:[UIFont boldSystemFontOfSize:18]]; 
    [titleView setTextColor:[UIColor blackColor]]; 
    titleView.text = title; 
    titleView.backgroundColor = [UIColor clearColor]; 
    [titleView sizeToFit]; 

    viewController.navigationItem.titleView = titleView; 
    [titleView release]; 

    viewController.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.1 green:0.2 blue:0.3 alpha:0.8]; 
} 
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 
} 


- (void)dealloc { 
    [super dealloc]; 
} 

@end 

मैं:

http://img.skitch.com/20100520-bpxjaca11h5xne5yakjdc2m6xx.png

यहाँ मेरी UINavigationBar उपवर्ग है पता है कि मैं पृष्ठभूमि बदलने के लिए एक श्रेणी का उपयोग कर सकते हैं छवि है, लेकिन मैं अभी भी नेविगेशन पट्टी शीर्षक

@implementation UINavigationBar (CustomImage) 
- (void)drawRect:(CGRect)rect { 
    UIImage *image = [UIImage imageNamed: @"navigation_bar_bgd.png"]; 
    [image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)]; 
} 
@end 

किसी भी सुझाव या अन्य समाधान के पाठ का रंग सेट करने के लिए सक्षम होना चाहते हैं? मैं मूल रूप से एक हल्की पृष्ठभूमि और फ्लिकर के ऐप नेविगेशन बार जैसे अंधेरे पाठ बनाना चाहता हूं

उत्तर

2

अपनी इच्छित रंग में UINavigationBar "tint" प्रॉपर्टी सेट करें।

+0

यह नेविगेशन बार की पृष्ठभूमि को बदलने के लिए काम करेगा, लेकिन मैं नेविगेशन बार के डिफ़ॉल्ट सफेद टेक्स्ट रंग को भी बदलना चाहता हूं, क्योंकि मैं एक हल्के रंगीन पृष्ठभूमि रंग का उपयोग करना चाहता हूं। उदाहरण के लिए यदि मैं एक का उपयोग करना चाहता था सफेद पृष्ठभूमि, मुझे डिफ़ॉल्ट सफेद पाठ को कुछ अंधेरे में बदलने में सक्षम होना चाहिए – funkadelic

2

[UIColor colorWithPatternImage:(UIImage*)image] बनाने और इसे NavBar की पृष्ठभूमि रंग संपत्ति में सेट करने का प्रयास करें। मैंने अभी तक यह कोशिश नहीं की है, लेकिन मैं अभी यह करूँगा।

4

मुझे पता नहीं है कि आपको यह पता चला है। लेकिन दूसरों के लिए इस समस्या को हो सकता है ...

आपको क्या करने की जरूरत है (इस मामले MyNavigationBar में अपने वर्ग के नाम करने के लिए अपने XIB में वर्ग निर्दिष्ट करने के लिए चेक सत्र 123 WWDC 2011

में है।