UIButton setBackgroundImage 恢复默认

     2023-03-17     132

关键词:

【中文标题】UIButton setBackgroundImage 恢复默认【英文标题】:UIButton setBackgroundImage back to default 【发布时间】:2013-09-20 22:39:22 【问题描述】:

我有一个在 UIStoryBoard 中创建的普通 RoundedRect UIButton。在某种情况下,我在按钮上调用setBackgroundImage 来改变它的外观。然后如何将 UIButton 的外观更改回设置背景图像之前的外观(默认 RoundedRect 外观)?调用[button setBackgroundImage:nil forState:UIControlStateNormal]; 似乎会导致按钮完全没有背景(完全透明)。

谢谢, 最大

【问题讨论】:

这取决于原始外观。你可以设置背景图片... 这是一个普通的 RoundedRect UIButton。我忘了把它放在问题中。我已经更新了。 【参考方案1】:

据我所知,当您将 UIButton 设置为 RoundedRect 时,您会告诉您的应用将默认图像设置为按钮的背景。

如果您随后使用自定义图像更改此背景,您的应用会放弃默认图像,并使用新图像进行切换。

很遗憾,您的应用不记得更改按钮之前的外观,并且无法返回。

无论如何,您可以通过以下方式重置您的 UIButton:

    删除并重新创建 创建类似于 RoundedRect UIButton 的自定义背景图像 使用 UIControlStates 设置按钮的外观

【讨论】:

如何摆脱 UIButton 图像和 UIButton 边框之间的填充?

】如何摆脱UIButton图像和UIButton边框之间的填充?【英文标题】:HowtogetridofthepaddingbetweenUIButtonimageandthebordersoftheUIButton?【发布时间】:2019-06-1022:10:42【问题描述】:我想去掉UIButton图像的顶部和UIButton的上边框以及UIButton图像的底... 查看详情

UIButton:根据titleLabel Text计算UIButton的高度

】UIButton:根据titleLabelText计算UIButton的高度【英文标题】:UIButton:calculateheightofUIButtonbasedontitleLabelText【发布时间】:2012-09-2118:32:29【问题描述】:我在自定义UITableViewCell中有一个自定义UIButton。我想根据按钮titleLabel的可变文本... 查看详情

如何删除多个 UIButton 或动态创建的特定 UIButton?

】如何删除多个UIButton或动态创建的特定UIButton?【英文标题】:HowtodeletemultipleUIButtonorparticularUIButtondynamicallycreated?【发布时间】:2012-12-1816:27:20【问题描述】:在我的应用程序中,在单击UIButton时,我需要动态创建多个UIButton并... 查看详情

uibutton的使用

使用UIButton时需要注意的是:1.UIButton的创建有专门的类方法(buttonWithType:,UILabel没有);2.UIButton常用的属性包括:frame、titile、tag等;3.UIButton使用addTarget方法关联处理方法,一个UIButton可以有多个不同的按钮响应方法,多个UIBut... 查看详情

我们在swiftui中作为 UIButton(Sender: UIButton) 有啥? [关闭]

】我们在swiftui中作为UIButton(Sender:UIButton)有啥?[关闭]【英文标题】:WhatdowehaveasUIButton(Sender:UIButton)inswiftui?[closed]我们在swiftui中作为UIButton(Sender:UIButton)有什么?[关闭]【发布时间】:2021-06-0406:02:52【问题描述】:在UIKit中,我通... 查看详情

为啥 Swift4 会强制转换 UIButton 数组!到 [UIButton?] 类型?

】为啥Swift4会强制转换UIButton数组!到[UIButton?]类型?【英文标题】:WhydoesSwift4castanarrayofUIButton!to[UIButton?]type?为什么Swift4会强制转换UIButton数组!到[UIButton?]类型?【发布时间】:2018-01-0316:31:43【问题描述】:我今天遇到了一个... 查看详情

如何在 UIButton 的右边缘对齐 UIButton 图像

】如何在UIButton的右边缘对齐UIButton图像【英文标题】:HowtoalignanUIButtonimageontherightedgeoftheUIButton【发布时间】:2015-11-3014:54:37【问题描述】:如何将图像对齐到UIButton的右边缘,以便它在所有设备上都保持在右边缘。下图显示了... 查看详情

如何防止 UIButton 的 imageView 占用整个 UIButton?

】如何防止UIButton的imageView占用整个UIButton?【英文标题】:HowtopreventimageViewofUIButtonfromtakingupentireUIButton?【发布时间】:2017-12-2615:50:42【问题描述】:我正在尝试以编程方式制作带有图标和标题的UIButton(默认情况下,图标应位... 查看详情

UIButton 根据 UIButton 转发事件和检索值

】UIButton根据UIButton转发事件和检索值【英文标题】:UIButtontoforwardevents&retrievevaluesaccordingtoUIButton【发布时间】:2011-06-2709:38:21【问题描述】:我有一个for循环,它显示7个UIButton,所有的方法都指向同一个视图(for循环,这就... 查看详情

UIButton 背景 VS UIButton imageview.view

】UIButton背景VSUIButtonimageview.view【英文标题】:UIButtonbackgroundVSUIButtonimageview.view【发布时间】:2012-02-0212:28:30【问题描述】:UIButton背景和UIButtonimageview.view有什么区别我试过myButton.imageView.image=[UIImageimageNamed:@"image.png&qu 查看详情

点击 UIButton 以编程方式创建另一个 UIButton

】点击UIButton以编程方式创建另一个UIButton【英文标题】:TapUIButtontocreateanotherUIButtonprogrammatically【发布时间】:2012-03-2722:53:05【问题描述】:我正在尝试以编程方式创建UIButton。我有一个名为“addCash”的按钮(已在界面生成器中... 查看详情

想要在单击相同的 UIButton 时从 UITableViewCell 更改正确的 UIButton 图像

】想要在单击相同的UIButton时从UITableViewCell更改正确的UIButton图像【英文标题】:WanttochangeacorrectUIButtonimagefromUITableViewCellonclicksameUIButton【发布时间】:2018-02-2006:29:54【问题描述】:我在UITableViewCell中有UIButton。当我单击UITableViewCe... 查看详情

iOS:将两个 UIButton 合并为一个 UIButton

】iOS:将两个UIButton合并为一个UIButton【英文标题】:iOS:CombinetwoUIButtonstooneUIButton【发布时间】:2014-03-2500:03:38【问题描述】:在故事板上我有两个UIButton。在我的UIViewController子类中,我有一个用于此按钮的IBAction方法。其中一个... 查看详情

单击选定的 UIButton 时未显示 UIButton 突出显示状态

】单击选定的UIButton时未显示UIButton突出显示状态【英文标题】:UIButtonHighlightedStatenotshowingwhenclickingoveraSelectedUIButton【发布时间】:2013-06-0322:55:46【问题描述】:当我点击一个已经被选中的按钮时,我希望我的UIButton显示高亮状... 查看详情

如何管理 UITableView + 动态自定义单元格(UIBUtton + UITextField + UIBUtton)插入?

】如何管理UITableView+动态自定义单元格(UIBUtton+UITextField+UIBUtton)插入?【英文标题】:HowtomanageUITableView+DynamicCustomCell(UIBUtton+UITextField+UIBUtton)Insertion?【发布时间】:2011-06-1011:19:37【问题描述】:我在管理UITableView时遇到问题。... 查看详情

UIButton 多个事件

】UIButton多个事件【英文标题】:UIButtonmultipleevents【发布时间】:2016-06-0108:25:05【问题描述】:我正在处理一个要求执行以下步骤的项目。显示初始计数为0的UIButton第一次触摸UIButton会增加计数第二次触摸UIButton,计数每1秒递增... 查看详情

第一个 UIButton 触发同一视图的另一个 UIbutton 事件

】第一个UIButton触发同一视图的另一个UIbutton事件【英文标题】:FirstUIButtonfiresanotherUIbuttoneventofsameview【发布时间】:2015-03-2308:11:06【问题描述】:我已经快速创建了两个UIButton并以编程方式添加了操作。当我尝试单击第一个按钮... 查看详情

UIButton 填充

】UIButton填充【英文标题】:UIButtonPadding【发布时间】:2013-11-2708:45:04【问题描述】:UIButton是否有等效的填充,就像在CSS中一样?我似乎对小按钮有问题,所以我想扩大按钮大小以使其易于点击。我修改了代码来调整UIButton的大... 查看详情