2011-12-08 11 views

उत्तर

10

मैंने एक उदाहरण किया जिसमें मेरे पास NaviagationBar के दाहिने तरफ दो बटन (यानी संपादित करें और +) थे।

1) आप एक NSMutableArray (अर्थात उदाहरण में "बटन") बना सकते हैं और जोड़ने के लिए UIBarButtonItem (अर्थात bi1 और NSMutableArray (अर्थात बटन उदाहरण में BI2))।

2) टूलबार में NSMutableArray (उदाहरण के लिए बटन) उदाहरण जोड़ें (उदाहरण के लिए UIToolbar *tools)।

3) नेविगेशनबार में टूलबार जोड़ें।

NSMutableArray *buttons = [[NSMutableArray alloc] initWithCapacity:2]; 
UIToolbar *tools = [[UIToolbar alloc] 
        initWithFrame:CGRectMake(0.0f, 0.0f, 90.0f, 55.01f)]; 
// Add bar button1. 

UIBarButtonItem *bi1 = [[UIBarButtonItem alloc] initWithTitle:@"Edit" style:UIBarButtonItemStylePlain target:self action:@selector(Edit:)]; 
bi1.style = UIBarButtonItemStyleBordered; 
bi1.width = 45; 
[buttons addObject:bi1]; 
//[bi1 release]; Do not release if ARC enabled. 

// Add bar button2. 
UIBarButtonItem *bi2 = [[UIBarButtonItem alloc] initWithTitle:@"+" style:UIBarButtonItemStylePlain target:self action:@selector(Add:)]; 
bi2.style = UIBarButtonItemStyleBordered; 
[buttons addObject:bi2]; 
//[bi2 release]; Do not release if ARC enabled. 

// Add buttons to toolbar and toolbar to nav bar. 
[tools setItems:buttons animated:NO]; 
//[buttons release]; Do not release if ARC enabled. 

// Add toolbar to nav bar. 
UIBarButtonItem *twoButtons = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
[tools release]; 
self.navigationItem.rightBarButtonItem = twoButtons; 
//[twoButtons release]; Do not release if ARC enabled. 
1

अपने xib फ़ाइल में ऐसा और हैडर

@property (nonatomic, retain) IBOutlet UIBarButtonItem *itemOne; 

में गुण या बस चर और फिर xib में इसे कनेक्ट।

1

कोड में एक नया UIToolbar बनाएं और टूलबार पर अपने बटन जोड़ें। तो फिर अपने नव निर्मित उपकरण पट्टी में self.navigationItem.rightBarButton सेट (ध्यान दें उदाहरण एआरसी के बिना है, इसलिए आप जारी करने के लिए कॉल निकालने की जरूरत हो सकती):

// create a toolbar to have two buttons in the right 
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 100, 44.01)]; 

// create the array to hold the buttons, which then gets added to the toolbar 
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:3]; 

// create a standard "add" button 
UIBarButtonItem* bi = [[UIBarButtonItem alloc] 
         initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addRow)]; 
bi.style = UIBarButtonItemStyleBordered; 
[buttons addObject:bi]; 
[bi release]; 

// create a spacer 
bi = [[UIBarButtonItem alloc] 
     initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; 
[buttons addObject:bi]; 
[bi release]; 

[buttons addObject:self.editButtonItem]; 

// stick the buttons in the toolbar 
[tools setItems:buttons animated:NO]; 

[buttons release]; 

// and put the toolbar in the nav bar 
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools]; 
1

यहाँ मैं आप नमूना कोड है कि मैं बटन के लिए इस्तेमाल रहा हूं साथ ही लेबल। आप लेबल और छवि के बजाय बटन बना सकते हैं जो मैंने बनाया था। मुझे आशा है कि यह आप

- (void) setLabelForPotraite { 

    bar = [self.navigationController navigationBar];  
    [bar setBackgroundColor:[UIColor clearColor]]; 
    barImg=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navImg.png"]]; 
    [bar addSubview:barImg]; 


    tick_img_lbl=[[UIImageView alloc]initWithFrame:CGRectMake(86, 6,34, 33)]; 
    tick_img_lbl.image=[UIImage imageNamed:@"tick-1.png"]; 
    [bar addSubview:tick_img_lbl]; 
    [tick_img_lbl release]; 

    tickCount_lbl=[[UILabel alloc] initWithFrame:CGRectMake(126, 2, 50, 40)]; 
    [email protected]""; 
    tickCount_lbl.font=[UIFont fontWithName:@"Arial" size:24.0]; 
    [tickCount_lbl setTextAlignment:UITextAlignmentCenter]; 
    tickCount_lbl.font = [UIFont boldSystemFontOfSize:24.0]; 
    tickCount_lbl.textColor=[UIColor whiteColor]; 
    tickCount_lbl.backgroundColor=[UIColor clearColor]; 
    [bar addSubview:tickCount_lbl]; 
    [tickCount_lbl release]; 

    cross_img_lbl=[[UIImageView alloc]initWithFrame:CGRectMake(181, 6, 34, 33)]; 
    cross_img_lbl.image=[UIImage imageNamed:@"x_green.png"]; 

    [bar addSubview:cross_img_lbl]; 
    [cross_img_lbl release]; 

    crossCount_lbl=[[UILabel alloc] initWithFrame:CGRectMake(221, 2, 50, 40)]; 
    [email protected]""; 
    crossCount_lbl.font=[UIFont fontWithName:@"Arial" size:24.0]; 
    crossCount_lbl.font = [UIFont boldSystemFontOfSize:24.0]; 
    crossCount_lbl.textColor=[UIColor whiteColor]; 
    [crossCount_lbl setTextAlignment:UITextAlignmentCenter]; 
    crossCount_lbl.backgroundColor=[UIColor clearColor]; 
    [bar addSubview:crossCount_lbl]; 
    [crossCount_lbl release]; 

    master_img_lbl=[[UIImageView alloc]initWithFrame:CGRectMake(269, 6, 34, 33)]; 
    master_img_lbl.image=[UIImage imageNamed:@"thumb.png"]; 
    [bar addSubview:master_img_lbl]; 
    [master_img_lbl release]; 

}

में मदद मिलेगी, तो समझ में नहीं तो फिर किसी भी समस्या plz मुझे सूचित करें।

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