大家好,
我需要帮助来创建如上图所示的按钮。
它们是多个按钮,用于切换到另一个 View ,下一个按钮用于显示隐藏按钮。
我想知道要使用哪个 UI 控件。
首选免费的即用型控件或代码示例。
非常感谢。
我按照 Mayur Joshi 的建议做了,但不明白为什么我不能在 ScrollView 中滚动按钮并且按钮上没有文字。
这是我的代码
- (void)viewDidLoad
{
[super viewDidLoad];
[scrollView setContentSize:CGSizeMake(500.0f, 50.0f)];
[self.view addSubview: scrollView];
UIButton *button1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[button1 setTitle:@"Button1" forState:UIControlStateNormal];
[button1 setFrame:CGRectMake(0.0F, 0.0F, 100.0F, 50.0F)];
[scrollView addSubview:button1];
[button1 release];
UIButton *button2 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[button2 setTitle:@"Button2" forState:UIControlStateNormal];
[button2 setFrame:CGRectMake(100.0F, 0.0F, 100.0F, 50.0F)];
[scrollView addSubview:button2];
[button2 release];
UIButton *button3 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[button3 setTitle:@"Button3" forState:UIControlStateNormal];
[button3 setFrame:CGRectMake(200.0F, 0.0F, 100.0F, 50.0F)];
[scrollView addSubview:button3];
[button3 release];
UIButton *button4 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[button4 setTitle:@"Button4" forState:UIControlStateNormal];
[button4 setFrame:CGRectMake(300.0F, 0.0F, 100.0F, 50.0F)];
[scrollView addSubview:button4];
[button4 release];
UIButton *button5 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
[button5 setTitle:@"Button5" forState:UIControlStateNormal];
[button5 setFrame:CGRectMake(400.0F, 0.0F, 100.0F, 50.0F)];
[scrollView addSubview:button5];
[button5 release];
}
you can download source code here
这是应用程序屏幕截图。
最佳答案
只需从按钮中删除释放方法即可。
实际上,当您声明按钮时
UIButton* btn1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];
它作为类方法而不是静态方法已经处于自动 Release模式。所以你不需要写
[btn1 release];
关于iphone - 他们如何在 iPhone 应用程序的附加图片中实现这种按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117197/