首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS 8选择的UISegmenetedControl出版社上的错误图像

iOS 8选择的UISegmenetedControl出版社上的错误图像
EN

Stack Overflow用户
提问于 2015-01-30 22:05:22
回答 1查看 206关注 0票数 2

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

右侧选择

左侧点击非选定选项卡

右侧点击,右侧选择

我已经尝试过一些事情,比如设置backgroundColor以清除,或者查看是否有我丢失的状态,但我似乎无法找到解决方案。

谢谢你的建议。

按照要求,下面是代码:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2015-04-12 21:20:14

在选择一个已经选定的段时,该段会变成灰色,原因是分段控件在同一时间丢失了所选和突出显示的状态。

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

代码语言:javascript
复制
self.feedTypeButton.setBackgroundImage(UIImage.imageWithColor(Colors.mediumBlue).resizableImageWithCapInsets(UIEdgeInsetsZero), forState:.Selected | .Highlighted, barMetrics: .Default)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28245416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档