我有一个自定义 UISegmentedControl。在 iOS 6 及以下版本中,它工作正常。在 iOS 7 下,它看起来很好,直到我按下控件,此时,分隔线图像在一瞬间看起来很奇怪。
这是我的代码:
UIImage *segmentSelected = [[UIImage imageNamed:@"segcontrol_sel.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
UIImage *segmentUnselected = [[UIImage imageNamed:@"segcontrol_unsel.png"]
resizableImageWithCapInsets:UIEdgeInsetsMake(6, 6, 6, 6)];
UIImage *segmentSelectedUnselected =
[UIImage imageNamed:@"segcontrol_sel_uns.png"];
UIImage *segUnselectedSelected =
[UIImage imageNamed:@"segcontrol_uns_sel.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];
当我按下 UISegmentedControl 时会发生什么可能会导致分隔线显示错误的任何想法?谢谢?