如何在iPhone中设置图像到UISegmentedControl?

我是iphone开发的新手.我创建了具有2个段的UISegmentedControl.我想显示每个片段的图片而不是title.Here是我的代码

NSArray *itemArray = [NSArray arrayWithObjects: @"segment1", @"segment2", nil];
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:itemArray];
segmentedControl.frame = CGRectMake(5,100,300,40);
segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;
segmentedControl.selectedSegmentIndex = 1;
[self.view addSubview:segmentedControl];
[segmentedControl release]; 

而不是显示标题,segment1和segment2它应该被替换为我有的图像.请帮助我.谢谢.

几乎完全是你所拥有的,只是通过一系列UIImages而不是NSStrings.

NSArray *itemArray = [NSArray arrayWithObjects:
    [UIImage imageNamed:@"segment1.png"],
    [UIImage imageNamed:@"segment2.png"],
    nil];
翻译自:https://stackoverflow.com/questions/3001313/how-to-set-image-to-the-uisegmentedcontrol-in-iphone

转载注明原文:如何在iPhone中设置图像到UISegmentedControl?