ios - 无法在按钮上加载 UIImage

标签 ios xcode uiimage

我想在按钮上添加UIImage,但是del.png无法在我的按钮上显示, 我能做什么?

我尝试了很多加载图片的方法,但没有效果,比如:

UIImage* delImage = [[UIImage alloc] initWithContentsOfFile:@"del.png"];

UIImage* delImage = [UIImage imageNamed:@"del.png"];

UIImage* delImage =[UIImage imageWithContentsOfFile:@"del.png"];

CalDelBtn *BookItem = [[CalDelBtn alloc] initWithFrame:CGRectMake(startPointX, startPointY, 75, 113) statuePicture:delImage];

请大家给我一些建议,谢谢!!

最佳答案

首先,您的图像可以加载

UIImage * image = [UIImage imageNamed:@"del.png"];

这是加载图像的最简单方法,因此它应该与自动发布的图像一起使用。

不要忘记将其添加到您的 xCode projet explorer 中!以下列出了您的图像通常无法显示的原因:https://stackoverflow.com/a/9698764/127493 .

然后,使用以下命令将其添加到您的按钮:

[button setBackgroundImage:image forState:UIControlStateNormal];

例如。有效吗?

关于ios - 无法在按钮上加载 UIImage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10680950/

相关文章:

ios - 在没有导航 Controller 的 UIViewController 中创建 UIToolbar

iphone - 将多个同名资源添加到 Xcode for iPhone

ios - UITableView 未正确提取 JSON

ios - 核心数据 - 如何初始化对象但不将其添加到持久存储?

objective-c - UIWebView - shouldStartLoadWithRequest - NSMutableURLRequest

objective-c - Apple 推送通知徽章编号

ios - SVN 忽略 '.a' 文件

iphone - 如何获取有关 imageWithContentsOfFile : completion? 的通知

ios - Swift:将 UIImage 设置为背景

ios - 如何像邮件一样在 UITextView 中显示图像并使其居中