如何使用 iOS 创建一个大的红色 UIButton? [英] How can I create a big, red UIButton with iOS?
本文介绍了如何使用 iOS 创建一个大的红色 UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 iOS,我将如何创建一个类似于在 iPhone 上删除联系人时使用的红色删除"按钮?
Using iOS, 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:
然后您制作一个以拉伸图像为背景的按钮并应用文本.
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.
这篇关于如何使用 iOS 创建一个大的红色 UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文