帮我!
我的代码如下:
if([SegmentRound selectedSegmentIndex] == 0) { UIcolor *newSelectedTintcolor2 = [UIcolor colorWithRed: 98/255.0 green:156/255.0 blue:247/255.0 Alpha:1.0]; [[[SegmentRound subvIEws] objectAtIndex:0] setTintcolor:newSelectedTintcolor2]; UIcolor *newSelectedTintcolor1 = [UIcolor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 Alpha:1.0]; [[[SegmentRound subvIEws] objectAtIndex:1] setTintcolor:newSelectedTintcolor1]; UIcolor *newSelectedTintcolor0 = [UIcolor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 Alpha:1.0]; [[[SegmentRound subvIEws] objectAtIndex:2] setTintcolor:newSelectedTintcolor0]; FLAGROUND=1; } if([SegmentRound selectedSegmentIndex] == 1) { UIcolor *newSelectedTintcolor1 = [UIcolor colorWithRed: 98/255.0 green:156/255.0 blue:247/255.0 Alpha:1.0]; [[[SegmentRound subvIEws] objectAtIndex:1] setTintcolor:newSelectedTintcolor1]; UIcolor *newSelectedTintcolor0 = [UIcolor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 Alpha:1.0]; [[[SegmentRound subvIEws] objectAtIndex:0] setTintcolor:newSelectedTintcolor0]; UIcolor *newSelectedTintcolor2 = [UIcolor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 Alpha:1.0]; [[[SegmentRound subvIEws] objectAtIndex:2] setTintcolor:newSelectedTintcolor2]; FLAGROUND=2; } if([SegmentRound selectedSegmentIndex] == 2) { UIcolor *newSelectedTintcolor0 = [UIcolor colorWithRed: 98/255.0 green:156/255.0 blue:247/255.0 Alpha:1.0]; [[[SegmentRound subvIEws] objectAtIndex:2] setTintcolor:newSelectedTintcolor0]; UIcolor *newSelectedTintcolor2 = [UIcolor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 Alpha:1.0]; [[[SegmentRound subvIEws] objectAtIndex:0] setTintcolor:newSelectedTintcolor2]; UIcolor *newSelectedTintcolor1 = [UIcolor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 Alpha:1.0]; [[[SegmentRound subvIEws] objectAtIndex:1] setTintcolor:newSelectedTintcolor1]; FLAGROUND=3; }
vIEwWillAppear中:
[SegmentRound setSelectedSegmentIndex:0];解决方法 我建议在你的条件之外创建两种颜色,使你的代码变小.然后,您可以使用foreach迭代您的细分:
UIcolor *selectedcolor = [UIcolor colorWithRed: 98/255.0 green:156/255.0 blue:247/255.0 Alpha:1.0];UIcolor *deselectedcolor = [UIcolor colorWithRed: 54/255.0 green:52/255.0 blue:48/255.0 Alpha:1.0];for (UIControl *subvIEw in [SegmentRound subvIEws]) { if ([subvIEw isSelected]) [subvIEw setTintcolor:selectedcolor]; else [subvIEw setTintcolor:deselectedcolor]; }总结
以上是内存溢出为你收集整理的iphone – 更改所选分段控件的颜色全部内容,希望文章能够帮你解决iphone – 更改所选分段控件的颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)