ios – 选中时避免使用UIButton反色

ios – 选中时避免使用UIButton反色,第1张

概述我有一个UIButton,其中包含正常和选定状态的不同图像.此外,我需要根据应用程序的主题更改按钮的色调. 但是当我将按钮设置为选定状态以切换图像时,它会反转其颜色. - (void)setLike:(BOOL)selected { self.likeButton.selected = selected; if (selected) { self.likeButto 我有一个UIbutton,其中包含正常和选定状态的不同图像.此外,我需要根据应用程序的主题更改按钮的色调.

但是当我将按钮设置为选定状态以切换图像时,它会反转其颜色.

- (voID)setlike:(BOol)selected {    self.likebutton.selected = selected;    if (selected) {        self.likebutton.tintcolor = [theme getTintcolor];    } else {        self.likebutton.tintcolor = [theme getlightcolor];    }}

正常状态

实际选择

期望选择

注意:我无法更改图像,因为此代码用于应用程序中具有不同选定和未选定图像的其他位置.

- (voID)setlike:(BOol)selected {    if (selected) {         [self.likebutton setimage:[UIImage imagenamed:@"liked"] forState:UIControlStatenormal];         self.likebutton.tintcolor = [theme getTintcolor];    } else {         [self.likebutton setimage:[UIImage imagenamed:@"like"] forState:UIControlStatenormal];         self.likebutton.tintcolor = [theme getlightBasecolor];    }}
解决方法 >在Interface Builder中找到您的按钮,并将其类型从System更改为Custom.这应该消除放大和反转图像以选择状态的效果. >打开Assets文件,其中定义了normal和Selected状态的两个图像.将“正常图像渲染为”设置为“原始图像”,将“选定图像”设置为“模板图像”.这应该会导致应用程序的默认色调仅应用于选定状态. 总结

以上是内存溢出为你收集整理的ios – 选中时避免使用UIButton反色全部内容,希望文章能够帮你解决ios – 选中时避免使用UIButton反色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1027209.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存