【发布时间】:2015-02-08 16:21:12
【问题描述】:
我有一个 UISegmentedContol,每个段内都有图像。在情节提要中,我将图像的背景颜色和色调设置为白色。 Now when one segment is selected, I am trying to change the background color only and keep the image tint to white (the same as the unselected segments) but I am unable to do so.这是我的代码:
- (IBAction)onSegmentValueChanged:(id)sender
{
UISegmentedControl *segment = (UISegmentedControl*)sender;
UIColor *tintcolor=UIColorFromRGB(0x3A0F3A);
for (int i=0; i<[segment.subviews count]; i++)
{
if ([[segment.subviews objectAtIndex:i]isSelected] )
{
[[segment.subviews objectAtIndex:i] setBackgroundColor:[UIColor purpleColor]];
[[segment.subviews objectAtIndex:i] setTintColor:[UIColor whiteColor]];
}
else
{
[[segment.subviews objectAtIndex:i] setBackgroundColor:tintcolor];
}
}
}
见下图:
https://www.dropbox.com/s/y93m3vtgr95e2dy/IMG_9249.PNG?dl=0
未选择的片段具有正确的背景颜色(紫色)和正确的图像色调(白色)。所选片段应具有带有白色图像色调的紫色背景,但它具有白色背景。
谢谢
【问题讨论】:
标签: ios objective-c uisegmentedcontrol