2010-11-22 14 views
1

UIToolBar'a orta konumda bir düğme koymak istiyorum. Aşağıdaki kodda hangi değişiklikleri yapmak zorundayım?iPhone'da bir UIToolBar'ın merkezine bir düğme koymak mümkün mü?

CGRect toolbarFrame = CGRectMake(0, 0, self.view.frame.size.width, 44); 
UIToolbar *mytoolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame]; 
mytoolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
mytoolbar.tintColor = [UIColor blackColor]; 
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"button 1" 
          style:UIBarButtonItemStylePlain target:self action:nil]; 
NSMutableArray *tools = [[NSMutableArray alloc] initWithObjects:button,nil]; 
[mytoolbar setItems:tools]; 
[self.view addSubview:mytoolbar]; 

cevap

5

Eğer initWithBarButtonSystemItem kullanarak, iki UIBarButtonItems oluşturursanız Bence: UIBarButtonSystemItemFlexibleSpace ve düğmenize önce bir koyun ve sonra diğer - ... sizin arzu merkezleme bu alırsınız

+0

Teşekkürler! Bu bana yardımcı oldu. –

1

oluştur UIBarButtonSystemItemFlexibleSpace tipindeki bir bar düğmesi.

UIBarButtonItem *spaceButton = 
    [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
          target:nil action:nil]; 
UIBarButtonItem *button = 
    [[UIBarButtonItem alloc] initWithTitle:@"button 1" style:UIBarButtonItemStylePlain 
          target:self action:nil]; 
NSMutableArray *tools = 
    [[NSMutableArray alloc] initWithObjects:spaceButton, button, spaceButton,nil]; 
[mytoolbar setItems:tools]; 
İlgili konular