【问题标题】:Wrong Image on iOS 8 Selected UISegmenetedControl PressiOS 8 Selected Segmented Control Press 上的错误图像
【发布时间】: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


【解决方案1】:

在选择已选择的段时,段变为灰色的原因是分段控件缺少同时选中和突出显示的状态。

在您的情况下,要解决问题,只需调用:

self.feedTypeButton.setBackgroundImage(UIImage.imageWithColor(Colors.mediumBlue).resizableImageWithCapInsets(UIEdgeInsetsZero), forState:.Selected | .Highlighted, barMetrics: .Default)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-12
    • 2015-12-06
    相关资源
    最近更新 更多