iphone - 他们如何在 iPhone 应用程序的附加图片中实现这种按钮?

标签 iphone objective-c ios cocoa-touch

multiple button with next to another

大家好,
我需要帮助来创建如上图所示的按钮。 它们是多个按钮,用于切换到另一个 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

这是应用程序屏幕截图。 button in scrollview screen shot

最佳答案

只需从按钮中删除释放方法即可。

实际上,当您声明按钮时

 UIButton* btn1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];

它作为类方法而不是静态方法已经处于自动 Release模式。所以你不需要写

 [btn1 release];

关于iphone - 他们如何在 iPhone 应用程序的附加图片中实现这种按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7117197/

相关文章:

iphone - UILabel 中的图标无法正确显示

ios - 点击手势识别器会干扰 UITextView 中的 URL 点击

objective-c - 如何最好地调试 objc_msgSend 中的崩溃?

ios - 如何删除子类 UITableViewCells 之间的分隔符?

ios - 通过替换 Windows 根 Controller 在多个 Storyboard之间移动

iphone - UITableViewCell 点击展开

iphone - CoreData 无法解决从 xml feed 检索数据并使用托管对象进行操作的错误

ios - 为 iOS 增强现实应用程序开发自定义过滤器

iphone - UISegmentedControl、UIToolbar 和 UINavigationItem

iphone - 将 NSMutableArray 的 UIButtons 标题分配给 NSMutableArray 的 UIButtons?