ios - 在 Objective-C 中设置 Button 的背景图片

标签 ios objective-c

我遇到无法将背景图像设置为 UIButton 的问题。我的按钮是一个彩色按钮,我想在按钮的背景上有一个图像。而且,我可以增加背景图像的大小。我的代码是:

在.h 中

@property (weak, nonatomic) IBOutlet UIButton *color1;

以.m 为单位

UIImage *colorimage = [UIImage imageNamed:@"57_bg_selected"];
[_color1 setBackgroundImage:colorimage forState:UIControlStateNormal];

我得到的是背景图像是踩在按钮上。

最佳答案

按钮应该是自定义类型来设置图像。再次验证您的代码。在 Storyboard 中将按钮设置为自定义类型。

关于ios - 在 Objective-C 中设置 Button 的背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32194636/

相关文章:

iOS-核心蓝牙

iphone - 自定义 UITableViewCell 变空的问题?

ios - controllerDidChangeContent 核心数据严重应用错误

ios - 由于NSUserDefaultsDidChangeNotification,UI在后台线程上发生了变化

ios - 为什么非零数字无法将 BOOL 属性设置为 YES?

objective-c - NSImageView 图像未在运行的应用程序中显示(但在界面生成器的 xib 中正确显示)

objective-c - iOS 的 SSH2 库

ios - 即使使用 UITableViewCellStyleSubtitle,detailTextLabel 也不会显示

ios - 什么会导致错误 "Assertion failure in -[UICollectionViewData layoutAttributesForItemAtIndexPath:]"?

ios - 类保留计数