使用iOS,我如何创建一个红色的“删除”按钮,类似于在iPhone上删除联系人时使用的按钮?
发布于 2009-09-15 16:22:01
首先从一个可伸展的图像开始:
然后,制作一个以拉伸图像为背景的按钮,并应用文本。
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];
显然,您需要调整框架的原点和大小以匹配您的应用程序,以及目标、选择器和标题。
发布于 2010-11-24 06:03:10
我还制作了一些buttons...retina和非视网膜版本
如果您想在单元格中使用它们,只需在cellForRowAtIndexPath中使用以下代码:
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];
发布于 2009-09-15 17:05:56
可能最简单的方法是在PSD层中抓取包含大量UI元素的this iPhone GUI Photoshop file,然后更改Photoshop中大按钮的色调并将其保存为PNG。
这样做的一个好处是,您还可以为按钮选中和/或高亮显示状态创建版本,并将图像分配给标准的UIButton。
https://stackoverflow.com/questions/1427818
复制相似问题