iphone – 为UIButton设置背景图像

iphone – 为UIButton设置背景图像,第1张

概述我是Objective C的新手。如何将此按钮的背景设置图像(图像已经在XCode中的资源文件夹中,“blue_button.png”)而不是clearColor?此外,我更喜欢使用图像作为按钮的形状,而不是UIButtonTypeRoundedRect。 btnClear = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain]; 我是Objective C的新手。如何将此按钮的背景设置为图像(图像已经在XCode中的资源文件夹中,“blue_button.png”)而不是clearcolor?此外,我更喜欢使用图像作为按钮的形状,而不是UIbuttonTypeRoundedRect。

btnClear = [[UIbutton buttonWithType:UIbuttonTypeRoundedRect] retain];btnClear.frame = CGRectMake(115,350,90,40);[btnClear setTitle:@"Clear" forState:UIControlStatenormal];btnClear.backgroundcolor = [UIcolor clearcolor];[btnClear addTarget:self action:@selector(clearaction:) forControlEvents:UIControlEventtouchUpInsIDe];[self.vIEw addSubvIEw:btnClear];

我知道如何在Interface Builder中执行此 *** 作,但我宁愿了解如何在XCode中执行此 *** 作。

琳达

解决方法 这样做:

UIbutton *btnClear = [[UIbutton alloc] init];btnClear = [[UIbutton buttonWithType:UIbuttonTypeCustom] retain];btnClear.frame = CGRectMake(115,200,40);[btnClear setTitle:@"Clear" forState:UIControlStatenormal];[btnClear setBackgroundImage:[UIImage imagenamed:@"blue_button.png"] forState:UIControlStatenormal];[btnClear addTarget:self action:@selector(clearaction:) forControlEvents:UIControlEventtouchUpInsIDe];[self.vIEw addSubvIEw:btnClear];
总结

以上是内存溢出为你收集整理的iphone – 为UIButton设置背景图像全部内容,希望文章能够帮你解决iphone – 为UIButton设置背景图像所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存