本文介绍了在UISegmentedcontrol中更改textColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的代码来更改UISegmentedcontrol中每个分段的textcolor如何更改特定段的textcolor?(例如索引2处的段)
I use below code for change textcolor of each segmented in UISegmentedcontrol how can I change textcolor of specific segment?(for example segment at index 2)
for (id seg in [segment subviews])
for (id label in [seg subviews])
if ([label isKindOfClass:[UILabel class]])
[label setTextColor:[UIColor redColor]];
推荐答案
我使用下面的代码来解决这个问题
i use below code for this problem
int eg=0;
for (id seg in [sg subviews])
{
int gg=sg.selectedSegmentIndex;
if(gg==2)
gg=0;
else if(gg==0)
gg=2;
if(eg==gg && eg!=1)
{
for (id label in [seg subviews])
if ([label isKindOfClass:[UILabel class]])
{
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont boldSystemFontOfSize:12]];
[label setTextColor:[UIColor colorWithRed:0.325 green:0.565 blue:0.788 alpha:1]];
}//if
}//if
else if(eg==1)
{
for (id label in [seg subviews])
if ([label isKindOfClass:[UILabel class]])
{
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont boldSystemFontOfSize:11]];
[label setTextColor:[UIColor grayColor]];
}//if
}//else if
else
{
for (id label in [seg subviews])
if ([label isKindOfClass:[UILabel class]])
{
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont boldSystemFontOfSize:11]];
[label setTextColor:[UIColor colorWithRed:0.888 green:0.888 blue:0.888 alpha:1]];
}//if
}//else
eg++;
}//for
这篇关于在UISegmentedcontrol中更改textColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!