ios - 带有自定义的 UIButton。按下时背景看起来很糟糕

标签 ios interface-builder uibutton

我有一个带有自定义背景的 UIButton,我在 Interface Builder 中设置了它(见图)。它看起来不错,但在按下状态下它变得非常难看(参见第二张图)。这是怎么回事?

正常:

see picture

按下:

enter image description here

最佳答案

[btn setBackgroundImage:[[UIImage imageNamed:@"button_red.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(12, 12, 20, 12)] forState:UIControlStateNormal];
[btn setBackgroundImage:[[UIImage imageNamed:@"button_red_pressed.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(12, 12, 20, 12)] forState:UIControlStateHighlighted];

这应该可以解决问题。

此外,将按钮样式更改为“自定义”,这将删除蓝色按钮背景。

关于ios - 带有自定义的 UIButton。按下时背景看起来很糟糕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9639179/

相关文章:

ios - 按钮和开关

iphone - 为什么这个 UIButton 不显示它的文本标签?

ios - 使用自动布局在 UIView 内水平居中 UILabel + UIImageView

ios - 从 NSArray 中移除对象

ios - 按下后 SwiftUI Toggle 将被禁用

ios - UIScrollView 还是 UIImageView?

xcode - 抑制 Xcode 的 "Full Screen Behavior"警告

macos - NSPredicateEditor 行模板不可在界面生成器中配置

iphone - 如何创建一个行为类似于 UIKeyboard (Numberpad) 的 UIButton 矩阵?

ios - 如何让 Cordova 应用程序在设备上运行以连接到 Node JS 服务器