【发布时间】:2015-01-30 22:05:22
【问题描述】:
我有一个带有 2 个按钮的 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)
【问题讨论】:
-
请向我们展示您的代码。
-
我也发现了这个。你找到解决问题的方法了吗?
标签: ios swift ios8 uisegmentedcontrol