在iOS 7之前,很容易将彩色图像添加到分段控制器中,但现在如果我向其添加图像,则只能使用默认的色调而不是实际颜色显示图像。
是否有人对此有所了解,如果有这样帮助我的话。
提前完成。
答案 0 :(得分: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];
答案 1 :(得分: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];
答案 2 :(得分:-1)
只需将segmentController tintcolor更改为UIColor clearColor,使用style controlstyleborder
SegmentControl.backgroundColor= [UIColor clearColor];
[SegmentControl setTintColor:[UIColor clearColor]];