2012-02-09 10 views
8

में सही बार्बटन Items मैं अपने नेविगेशन बार के दाहिने भाग पर दो बटन जोड़ने के लिए UINavigationBar की rightBarButtonItems संपत्ति का उपयोग कर रहा हूं। क्या इन दोनों बटनों के बीच अंतर को व्यापक बनाना संभव है?सही स्थान पर UBavigationBar

धन्यवाद

उत्तर

6

आप अपने दो बटन के बीच एक UIBarButtonSystemItemFlexibleSpace आइटम जोड़ सकते हैं।

UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                     target:nil 
                     action:nil]; 
+0

धन्यवाद, यह काम करता है। लेकिन मैं चौड़ाई कैसे निर्दिष्ट करूं? – atnatn

+3

मुझे लगता है कि मुझे 'UIBarButtonSystemItemFixedSpace' का उपयोग करना चाहिए: डी – atnatn

+0

@atnatn शायद 'item.width' काम करता है, मैंने परीक्षण नहीं किया है। – fannheyward

1

मैं अपने स्थिति में काम करने के लिए लचीला स्थान प्राप्त करने में सक्षम नहीं था, लेकिन यहाँ कोड मैं rightBarButtonItem स्थिति करने में सक्षम हो के लिए इस्तेमाल किया है: ध्यान दें, मैं UIView के चारों ओर एक सीमा रख सकते हैं ताकि आप देख सकते हैं ऐसा लगता है कि वहां छवि है।

UIView *containerView = [[UIView alloc] initWithFrame:CGRectMake(89,40,100,30)]; 
containerView.layer.borderColor = [[UIColor redColor] CGColor]; 
containerView.layer.borderWidth = 1.0; 
UIImage *image = [UIImage imageNamed:@"nav-icon.png"]; 
UIButton *navigationButton = [UIButton buttonWithType:UIButtonTypeCustom]; 
[navigationButton setFrame:CGRectMake(67,0,25,25)]; 
[navigationButton setImage:image forState:UIControlStateNormal]; 
[containerView addSubview:navigationButton]; 

UIBarButtonItem *navigationBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:containerView]; 

self.navigationItem.rightBarButtonItem = navigationBarButtonItem; 
संबंधित मुद्दे