2012-01-19 14 views
9

में "अब बजाना" UIBarButtonItem में एक पंक्ति में UIBarButtonItem में दो पंक्ति कैसे डाल सकते हैं।हम नेविगेशन बार

UIBarButtonItem *flipButton = [[UIBarButtonItem alloc] 

           initWithTitle:@"Now Playing" 

           style:UIBarButtonItemStyleBordered 

           target:self 

           action:@selector(flipView)]; 


    self.navigationItem.rightBarButtonItem = flipButton; 

तो मैं बीच में पु लाइन ब्रेक करना चाहते हैं -: मैं, दो पंक्तियों में यह डाल करने के लिए की तरह "अब" ay शीर्ष निम्न कोड पंक्ति और "बजाना" bottom.I पर है लिखा है है "अभी खेल रहे है"। तो कृपया मेरी मदद करो।

+0

"अब \ n बजाना" के बारे में कैसे? – barley

+0

क्षमा करें, यह काम नहीं करता है। –

+0

ठीक है। ऐसा लगता है कि यह एक डुप्लिकेट है। लेकिन ऐसा लगता है कि कोई आसान तरीका नहीं है ... http://stackoverflow.com/questions/2614098/how-can-i-make-the-text-of-a-uibarbuttonitem-wrap-to-two-lines – barley

उत्तर

4
- (void)createCustomRightBarButton_ 
{ 
    UILabel * addCustomLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 64, 25)] autorelease]; 
    addCustomLabel.text [email protected]"Now\nPlaying"; 
    addCustomLabel.textColor = [UIColor whiteColor]; 
    addCustomLabel.font = [UIFont boldSystemFontOfSize:11]; 
    addCustomLabel.numberOfLines = 2; 
    addCustomLabel.backgroundColor = [UIColor clearColor]; 
    addCustomLabel.textAlignment = UITextAlignmentCenter; 

    CGSize size = addCustomLabel.bounds.size; 

    UIGraphicsBeginImageContext(size);  
    CGContextRef context = UIGraphicsGetCurrentContext();  
    [addCustomLabel.layer renderInContext: context]; 
    CGImageRef imageRef = CGBitmapContextCreateImage(context); 
    UIImage * img = [UIImage imageWithCGImage: imageRef]; 
    CGImageRelease(imageRef); 
    CGContextRelease(context); 

    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithImage:img 
                      style:UIBarButtonItemStyleBordered 
                      target:self 
                      action:@selector(flipView)] 
               autorelease]; 
} 
+0

I पाया गया कि टेक्स्ट रंग को नजरअंदाज कर दिया गया था और नेविगेशन आइटम द्वारा डिफ़ॉल्ट नीली हमेशा लागू की जा रही थी। यदि आप रंग बदलना चाहते हैं, तो UIBarButtonItem के tintColor को सेट करें। – Sky

+0

खासकर नए उपकरणों पर, यदि आप इस कोड को कॉपी/पेस्ट करते हैं तो आपको अस्पष्ट दिखने वाला टेक्स्ट मिल जाएगा। इसके आस-पास पहुंचने के लिए आप आसानी से फ़ॉन्ट/फ्रेम आकार बढ़ा सकते हैं, और फिर यूआईएममेज के कन्स्ट्रक्टर के माध्यम से स्केल कर सकते हैं। – Sky

0

आप अपने बार बटन के अंदर customView के रूप में एक UIButton होस्ट कर सकते हैं (या तो बार बटन आइटम customView सेट या आप अपने UIBarButtonItem के शीर्ष पर सीधे एक खींच सकते हैं), एक आउटलेट के रूप में यह ऊपर हुक, तो करते हैं,

-(void) viewDidLoad 
{ 
    //... 
    self.customButton.titleLabel.numberOfLines = 2; 
    self.customButton.suggestionsButton.titleLabel.lineBreakMode = UILineBreakModeWordWrap; 
    self.customButton.suggestionsButton.titleLabel.textAlignment = UITextAlignmentCenter; 
} 

जो मेरे मामले में हो जाता है

enter image description here

9

हाँ आप कर सकते हैं। यह करना काफी आसान है। एक मल्टीलाइन बटन बनाएं और इसका इस्तेमाल करें। "चाल" शीर्षक लेबल नंबरऑफलाइन संपत्ति सेट करना है ताकि इसे मल्टीलाइन पसंद आए।

UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom]; 
button.titleLabel.numberOfLines = 0; 
[button setTitle:NSLocalizedString(@"Now\nPlaying", nil) forState:UIControlStateNormal]; 
[button sizeToFit]; 

self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 

आप कस्टम के एक बटन प्रकार यह आप सब कुछ ... चयनित राज्य, आदि जो यहाँ नहीं दिखाया गया है हाथ में समस्या के लिए ध्यान केंद्रित जवाब रखने के लिए कॉन्फ़िगर करने की उम्मीद है निर्दिष्ट करते हैं।

1

enter image description here enter image description here

मैं अपने आप को द्वारा 2 पीएनजी चित्र बनाने, और यह अच्छा लग रहा है।

UIImage *img = [UIImage imageNamed:@"nowplaying.png"]; 
UIBarButtonItem *nowPlayingButtonItem = [[[UIBarButtonItem alloc] initWithImage:img style:UIBarButtonItemStyleBordered target:delegate action:@selector(presentNowPlayingMovie)] autorelease]; 
संबंधित मुद्दे