Iphone 如何添加图像&;是否将系统栏按钮项添加到UISegmentedControl?

Iphone 如何添加图像&;是否将系统栏按钮项添加到UISegmentedControl?,iphone,uibarbuttonitem,uisegmentedcontrol,Iphone,Uibarbuttonitem,Uisegmentedcontrol,我有一个UISegmentedControl作为导航栏的右栏按钮项。这是通过以下代码实现的 UISegmentedControl *segmentedControl = [ [UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Segment1",@"Segment2",nil]]; [segmentedControl addTarget:self action:@selector(segmentClicked

我有一个
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]; 
上面的代码很好,它将显示一个带有两段“Segment1”和“Segment2”的分段控件

但是我想显示一个图像而不是分段1&一个系统栏按钮(比如说
uibarbuttonsystemmadd
)而不是分段2

图像可以通过代码插入到分段控制中

UISegmentedControl *segmentedControl = [ [UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:[UIImage imageNamed:@"<image_name.image_type>"],???????,nil]];
UISegmentedControl*segmentedControl=[[UISegmentedControl alloc]initWithItems:[NSArray arrayWithObjects:[UIImage ImageName:@”“],??,nil]];
但是我不知道如何将
UIBarButtonSystemItemAdd
包含在“替换”中


提前感谢。

此代码可能会解决您的问题。这解决了我同时面临的问题。但不要认为这是正确的。我得到了需要显示的所需内容。使用两个按钮可以很好地工作

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];

此代码可能会解决您的问题。这解决了我同时面临的问题。但不要认为这是正确的。我得到了需要显示的所需内容。使用两个按钮可以正常工作

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];

我们无法在段控制器中添加选项卡栏项我们无法在段控制器中添加选项卡栏项