2011-09-13 14 views
1

私は、ナビゲーションバーの右のバーボタン項目としてUISegmentedControlを持っています。これは、上記のコード罰金はUISegmentedControlに画像とシステムバーのボタン項目を追加するにはどうすればいいですか?

UISegmentedControl *segmentedControl = [ [UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Segment1",@"Segment2",nil]]; 

[segmentedControl addTarget:self action:@selector(segmentClicked) forControlEvents:UIControlEventValueChanged]; //Where segmentClicked is the method for segment click action 

segmentedControl.frame = CGRectMake(0, 0, 90, 35); 

UIBarButtonItem *rightBaritem = [ [UIBarButtonItem alloc] initWithCustomView:segmentedControl]; 

[segmentedControl release]; 

self.navigationItem.rightBarButtonItem = rightBaritem; 

[rightBaritem release]; 

...次のコードによって達成されると、それは二つのセグメント「セグメント1」&「セグメント2」とセグメント化されたコントロールが表示されます。代わりにセグメント2

しかし、私が代わりにの画像を表示したいセグメント1 &システムバーボタン(UIBarButtonSystemItemAddセイ)。

画像は、コードによってセグメント化コントロールに挿入することができ、

UISegmentedControl *segmentedControl = [ [UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:[UIImage imageNamed:@"<image_name.image_type>"],???????,nil]]; 

しかし、私は???????の代わりにUIBarButtonSystemItemAddを含める方法を知りません。

事前に感謝..

答えて

1

このコードは、あなたのproblem.Thisを解決することが、私は同じtime.Butに直面していた私の問題は、これは正確なone.Iが希望されIを得ているとは思わない解決表示する必要があります。これは2つのボタンでうまく動作します。

UISegmentedControl *doneButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]]; 
     doneButton.momentary = YES; 
     doneButton.frame = CGRectMake(240, 7.0f, 70.0f, 30.0f); 
     doneButton.tintColor = [UIColor blackColor]; 
     [doneButton addTarget:self action:@selector(Done:) forControlEvents:UIControlEventValueChanged]; 
     [menustyle addSubview:doneButton]; 
     [doneButton release]; 

     doneButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Close"]]; 
     doneButton.momentary = YES; 
     doneButton.frame = CGRectMake(10, 7.0f, 70.0f, 30.0f); 
     doneButton.tintColor = [UIColor blackColor]; 
     [doneButton addTarget:self action:@selector(Krishna:) forControlEvents:UIControlEventValueChanged]; 
     [menustyle addSubview:doneButton]; 
     [doneButton release]; 
+0

セグメントコントローラにタブバーアイテムを追加できません –

関連する問題