iphone – 更改所选分段控件的颜色

iphone – 更改所选分段控件的颜色,第1张

概述在我的应用程序中,我能够更改所选分段控件的颜色.但是为另一个索引而不是选定的索引更改颜色.我可以在索引中找到任何错误. 帮我! 我的代码如下: if([SegmentRound selectedSegmentIndex] == 0) { UIColor *newSelectedTintColor2 = [UIColor colorWithRed: 98/255.0 gre 在我的应用程序中,我能够更改所选分段控件的颜色.但是为另一个索引而不是选定的索引更改颜色.我可以在索引中找到任何错误.

帮我!

我的代码如下:

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 – 更改所选分段控件的颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1068065.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存