如何使用iPhone SDK创建一个大的红色UIButton? [英] How can I create a big, red UIButton with the iPhone SDK?

查看:103
本文介绍了如何使用iPhone SDK创建一个大的红色UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Using the iPhone SDK, how would I go about creating a red "delete" button similar to the one used when deleting contacts on the iPhone?

推荐答案

首先从可伸缩的图像开始:

You first start with a stretchable image:

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

然后你创建一个拉伸图像作为背景的按钮并应用文本。

Then you make a button with the stretched image as the background and apply text.

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];

显然,您需要调整框架原点和尺寸以匹配您的应用,以及目标,选择器和标题。

Obviously, you will need to adjust the frame origin and size to match your app, as well as the target, selector, and title.

这篇关于如何使用iPhone SDK创建一个大的红色UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆