2

在 iOS 7 之前,将彩色图像添加到段控制器很容易,但现在如果我向其中添加图像,则只有图像在默认色调颜色下可见,而不是实际颜色。

有没有人对此有想法,如果有,请帮助我。

提前谢谢。

4

3 回答 3

3

修复它:imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal

UIImage *segmentImage = [UIImage imageNamed:@"Example"];

if ([UIImage instancesRespondToSelector:@selector(imageWithRenderingMode:)]) {
     segmentImage = [segmentImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
}

[self.control insertSegmentWithImage:segmentImage atIndex:i animated:NO];
于 2013-10-08T11:47:00.250 回答
0

这可能会帮助你

UIImage *segmentSelected = [[UIImage imageNamed:@"Off.png"]
                            resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
UIImage *segmentUnselected = [[UIImage imageNamed:@"On.png"]
                              resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
UIImage *segmentSelectedUnselected =
[UIImage imageNamed:@"dividerOn.png"];
UIImage *segUnselectedSelected =
[UIImage imageNamed:@"dividerOff.png"];

[[UISegmentedControl appearance] setBackgroundImage:segmentUnselected
                                           forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:segmentSelected
                                           forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setBackgroundImage:segmentUnselected
                                           forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

[[UISegmentedControl appearance] setDividerImage:segUnselectedSelected
                             forLeftSegmentState:UIControlStateNormal // | UIControlStateHighlighted
                               rightSegmentState:UIControlStateSelected
                                      barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segUnselectedSelected
                             forLeftSegmentState:UIControlStateHighlighted
                               rightSegmentState:UIControlStateSelected
                                      barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected
                             forLeftSegmentState:UIControlStateSelected
                               rightSegmentState:UIControlStateNormal //| UIControlStateHighlighted)
                                      barMetrics:UIBarMetricsDefault];
[[UISegmentedControl appearance] setDividerImage:segmentSelectedUnselected
                             forLeftSegmentState:UIControlStateSelected
                               rightSegmentState:UIControlStateHighlighted
                                      barMetrics:UIBarMetricsDefault];

UIFont *font = [UIFont systemFontOfSize:16.0f];
UIColor *textColor = [UIColor darkGrayColor];
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
                            font, @"NSFontAttributeName",
                            textColor, @"NSForegroundColorAttributeName",
                            nil];

[[UISegmentedControl appearance] setTitleTextAttributes:attributes
                                               forState:UIControlStateNormal];
于 2013-10-04T05:53:46.043 回答
-1

只需将 segmentController tintcolor 更改为 UIColor clearColor,使用样式 controlstyleborder

SegmentControl.backgroundColor= [UIColor clearColor];
[SegmentControl setTintColor:[UIColor clearColor]];
于 2013-10-09T12:09:33.517 回答