5

के बजाय खाली सफेद बॉक्स प्रदर्शित करना मुझे यकीन नहीं है कि मैं क्या गलत कर रहा हूं। फ़ाइल का नाम सही है, शैली को सादा करने के लिए सेट किया गया है। लेकिन मुझे अपनी छवि के आकार का एक बैंक सफेद बॉक्स मिल रहा है। मैं UINavigationController का उपयोग कर Im।UIBarButtonItem का उपयोग करके टूलबार में एक छवि जोड़ने में समस्या, छवि

कृपया सहायता करें और अग्रिम धन्यवाद।

** एफवाईआई मैं उद्देश्य सी के लिए नया नया हूं इसलिए मुझे बहुत मुश्किल नहीं है। ;)

UIBarButtonItem *toolbarChannelGuideButton = [[UIBarButtonItem alloc] 
    initWithImage:[UIImage imageNamed:@"channel-guide-button.png"] 
    style:UIBarButtonItemStylePlain 
    target:self 
    action:@selector(action:)]; 


self.toolbarItems = [NSArray arrayWithObjects:toolbarChannelGuideButton, nil]; 
[toolbarChannelGuideButton release]; 

उत्तर

9

जाँच कारण यह सफेद मुखौटा निर्माण कर रहा था, क्योंकि UIToolBar does not के द्वारा उस पर रंग छवियों की अनुमति चूक। इसे पूरा करने का तरीका UIImage बना रहा है, फिर उस छवि पर UIButton असाइन करें। फिर कस्टम दृश्य के रूप में UIButton के साथ का उपयोग करके UIBarButton बनाएं।

कोड:

 //Load the image 
    UIImage *buttonImage = [UIImage imageNamed:@"your-image.png"]; 

    //create the button and assign the image 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [button setImage:buttonImage forState:UIControlStateNormal]; 

    //sets the frame of the button to the size of the image 
    button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height); 

    //creates a UIBarButtonItem with the button as a custom view 
    UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button]; 



    self.toolbarItems = [NSArray arrayWithObjects:customBarItem, nil]; 
    [customBarItem release]; 
+0

धन्यवाद! यह पूरी तरह से काम किया ... – manderson

+0

UIButtonTypeCustom मेरे लिए यह तय किया। मैं गोलाकार एक का उपयोग कर रहा था – coolcool1994

-1

क्या चैनल-गाइड-बटन.png परियोजना से संबंधित है?

आप इस तरह इस बाहर तोड़ सकता है:

UIImage *image = [UIImage imageNamed:@"channel-guide-button.png"]; 
NSLog(@" image = %p", image); 
UIBarButtonItem *toolbarChannelGuideButton = [[UIBarButtonItem alloc] 
    initWithImage:image 
    style:UIBarButtonItemStylePlain 
    target:self 
    action:@selector(action:)]; 

या सिर्फ अपनी परियोजना ;-)

+0

मैं वहाँ में अपने प्रोजेक्ट में जाँच की और हाँ अपनी। मैंने एक एनएसएलओजी भी चलाया जिसने इसे निम्न स्तर की संख्या प्रदर्शित की। –

+0

छवि = 0x6b45340 यह कंसोल –

+0

ओह ठीक है में प्रदर्शित होता है। एफडब्ल्यूआईडब्ल्यू, मैं आम तौर पर initWithCustomView के साथ UIBarButtonItem बनाता हूं: और इसके साथ जुड़े छवि के साथ UIButton में पास करता हूं। मैं कल कोड उदाहरण पोस्ट करूंगा। – westsider

1

आप नीचे दिए गए का उपयोग कर सकते iOS 7 के साथ शुरू:

UIImage *image = [[UIImage imageNamed:@"myImage.png"]; 
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStylePlain target:self action:@selector(YOUR_METHOD:)];