我有一个有两个按钮的UISegmentedControl。我为.Normal、.Selected和.Highlighted设置了它们的背景图像。在iOS 7中,一切都是完美的,但在iOS8中几乎是完美的。当您正常使用按钮并且只点击未被选中的按钮时,一切都会正常工作。但由于某种原因,在iOS 8中,当您按下已经选定的按钮时,您将得到一个灰色背景而不是选定的图像。下面的图片展示了我的意思。
右侧选择

左侧点击非选定选项卡

右侧点击,右侧选择

我已经尝试过一些事情,比如设置backgroundColor以清除,或者查看是否有我丢失的状态,但我似乎无法找到解决方案。
谢谢你的建议。
按照要求,下面是代码:
self.feedTypeButton.setBackgroundImage(UIImage.imageWithColor(UIColor(hex: "#cee4ee")).resizableImageWithCapInsets(UIEdgeInsetsZero), forState: .Normal, barMetrics: .Default)
self.feedTypeButton.setBackgroundImage(UIImage.imageWithColor(Colors.blue).resizableImageWithCapInsets(UIEdgeInsetsZero), forState: .Selected, barMetrics: .Default)
self.feedTypeButton.setBackgroundImage(UIImage.imageWithColor(Colors.mediumBlue).resizableImageWithCapInsets(UIEdgeInsetsZero), forState: .Highlighted, barMetrics: .Default)
var dividerImage = UIImage.imageWithColor(Colors.blue, size: CGSize(width: 1, height: 28)).resizableImageWithCapInsets(UIEdgeInsetsZero)
self.feedTypeButton.setDividerImage(dividerImage, forLeftSegmentState: .Selected, rightSegmentState: .Normal, barMetrics: .Default)
self.feedTypeButton.setDividerImage(dividerImage, forLeftSegmentState: .Normal, rightSegmentState: .Selected, barMetrics: .Default)
self.feedTypeButton.setDividerImage(dividerImage, forLeftSegmentState: .Normal, rightSegmentState: .Normal, barMetrics: .Default)
self.feedTypeButton.setTitleTextAttributes([ NSForegroundColorAttributeName: Colors.gray, NSFontAttributeName: UI.regularFontOfSize(13) ], forState: .Normal)
self.feedTypeButton.setTitleTextAttributes([ NSForegroundColorAttributeName: Colors.white, NSFontAttributeName: UI.boldFontOfSize(15)], forState: .Selected)
self.feedTypeButton.setTitleTextAttributes([ NSForegroundColorAttributeName: Colors.white ], forState: .Highlighted)发布于 2015-04-12 21:20:14
在选择一个已经选定的段时,该段会变成灰色,原因是分段控件在同一时间丢失了所选和突出显示的状态。
在您的情况下,要解决这个问题,只需调用:
self.feedTypeButton.setBackgroundImage(UIImage.imageWithColor(Colors.mediumBlue).resizableImageWithCapInsets(UIEdgeInsetsZero), forState:.Selected | .Highlighted, barMetrics: .Default)https://stackoverflow.com/questions/28245416
复制相似问题