在我的应用程序中,我能够更改所选段控件的颜色。但是颜色会更改为另一个索引而不是所选索引。我可以在索引中找到任何错误。
帮我!
我的代码如下:
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;
}
viewwill出现:
[SegmentRound setSelectedSegmentIndex:0];