事情是,如果我使用文字,我可以添加我想要的段,但如果我使用图像意味着我无法在iPhone上添加超过6段。
帮助我。
UIImage* resetImage = [UIImage imageNamed:@"Reset_V1"];
UIImage* wlwwImage = [UIImage imageNamed:@"Reset_V1"];
UIImage* huImage = [UIImage imageNamed:@"HU_PI_V1"];
UIImage* panImage = [UIImage imageNamed:@"Panning_V1"];
UIImage* disImage = [UIImage imageNamed:@"Distance_V1"];
UIImage* areaImage = [UIImage imageNamed:@"Reset_V1"];
UIImage* clrImage = [UIImage imageNamed:@"Clear_V1"];
UIImage* presetImage = [UIImage imageNamed:@"Presets_V1"];
mySegments = [[NSArray alloc] initWithObjects: wlwwImage,panImage,huImage,disImage,areaImage,resetImage,clrImage,presetImage, nil];
segmentControl = [[UISegmentedControl alloc] initWithItems:mySegments];
CGRect myFrame = CGRectMake(0, 65, 320, 35);
segmentControl.frame = myFrame;
[segmentControl addTarget:self action:@selector(whichSegment:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:segmentControl];
答案 0 :(得分:0)
我尝试使用相同的代码并且正常工作
的输出:强>
的代码:强>
UIImage* resetImage = [UIImage imageNamed:@"Image"];
UIImage* wlwwImage = [UIImage imageNamed:@"Image"];
UIImage* huImage = [UIImage imageNamed:@"Image"];
UIImage* panImage = [UIImage imageNamed:@"Image"];
UIImage* disImage = [UIImage imageNamed:@"Image"];
UIImage* areaImage = [UIImage imageNamed:@"Image"];
UIImage* clrImage = [UIImage imageNamed:@"Image"];
UIImage* presetImage = [UIImage imageNamed:@"Image"];
UIImage* presetImage1 = [UIImage imageNamed:@"Image"];
UIImage* presetImage2= [UIImage imageNamed:@"Image"];
UIImage* presetImage3= [UIImage imageNamed:@"Image"];
NSArray *mySegments = [[NSArray alloc] initWithObjects: wlwwImage,panImage,huImage,disImage,areaImage,resetImage,clrImage,presetImage,presetImage1,presetImage2,presetImage3, nil];
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:mySegments];
CGRect myFrame = CGRectMake(0, 65, 320, 35);
segmentControl.frame = myFrame;
[self.view addSubview:segmentControl];
下载演示项目
Link
<小时/> 如果您的图片路径无效,则仅显示具有正确图片的细分
代码(有bug)
// Do any additional setup after loading the view, typically from a nib.
UIImage* resetImage = [UIImage imageNamed:@"Image"];
UIImage* wlwwImage = [UIImage imageNamed:@"Image"];
UIImage* huImage = [UIImage imageNamed:@"Image"];
UIImage* panImage = [UIImage imageNamed:@"Image"];
UIImage* disImage = [UIImage imageNamed:@"Image"];
UIImage* areaImage = [UIImage imageNamed:@"Image1"]; // wrong image name
UIImage* clrImage = [UIImage imageNamed:@"Image1"]; // wrong image name
UIImage* presetImage = [UIImage imageNamed:@"Image1"]; // wrong image name
UIImage* presetImage1 = [UIImage imageNamed:@"Image1"]; // wrong image name
UIImage* presetImage2= [UIImage imageNamed:@"Image1"]; // wrong image name
UIImage* presetImage3= [UIImage imageNamed:@"Image1"]; // wrong image name
NSArray *mySegments = [[NSArray alloc] initWithObjects: wlwwImage,panImage,huImage,disImage,areaImage,resetImage,clrImage,presetImage,presetImage1,presetImage2,presetImage3, nil];
UISegmentedControl *segmentControl = [[UISegmentedControl alloc] initWithItems:mySegments];
CGRect myFrame = CGRectMake(0, 65, 320, 35);
segmentControl.frame = myFrame;
[self.view addSubview:segmentControl];