首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用iOS创建一个红色的大UIButton?

如何使用iOS创建一个红色的大UIButton?
EN

Stack Overflow用户
提问于 2009-09-15 15:16:02
回答 4查看 57.7K关注 0票数 53

使用iOS,我如何创建一个红色的“删除”按钮,类似于在iPhone上删除联系人时使用的按钮?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2009-09-15 16:22:01

首先从一个可伸展的图像开始:

alt text http://grab.by/4lP

然后,制作一个以拉伸图像为背景的按钮,并应用文本。

代码语言:javascript
复制
UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleButton setFrame:CGRectMake(kLeftMargin, 10, self.view.bounds.size.width - kLeftMargin - kRightMargin, 52)];
[sampleButton setTitle:@"Button Title" forState:UIControlStateNormal];
[sampleButton setFont:[UIFont boldSystemFontOfSize:20]];
[sampleButton setBackgroundImage:[[UIImage imageNamed:@"redButton.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];
[sampleButton addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:sampleButton];

显然,您需要调整框架的原点和大小以匹配您的应用程序,以及目标、选择器和标题。

票数 84
EN

Stack Overflow用户

发布于 2010-11-24 06:03:10

我还制作了一些buttons...retina和非视网膜版本

如果您想在单元格中使用它们,只需在cellForRowAtIndexPath中使用以下代码:

代码语言:javascript
复制
UIButton *sampleButton = [UIButton buttonWithType:UIButtonTypeCustom];
[sampleButton setFrame:[cell.contentView frame]];
[sampleButton setFrame:CGRectMake(0, 0, cell.bounds.size.width-20, 44)];
[sampleButton setBackgroundImage:[UIImage imageNamed:@"button_red.png"] forState:UIControlStateNormal];
[cell addSubview:sampleButton];

票数 62
EN

Stack Overflow用户

发布于 2009-09-15 17:05:56

可能最简单的方法是在PSD层中抓取包含大量UI元素的this iPhone GUI Photoshop file,然后更改Photoshop中大按钮的色调并将其保存为PNG。

这样做的一个好处是,您还可以为按钮选中和/或高亮显示状态创建版本,并将图像分配给标准的UIButton。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1427818

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档