【问题标题】:iPhone Create UIButton in IB for custom UIViewiPhone 在 IB 中为自定义 UIView 创建 UIButton
【发布时间】:2011-11-09 14:56:07
【问题描述】:

我的应用中有一个自定义 UIView(在没有 InterfaceBuilder 的情况下创建)。我想在其中插入一个 UIButton,但我不想以编程方式创建按钮。 所以我想在Interface Builder中创建UIButton,然后放到我的视图中。

我的第一步是: 1)从“空”模板创建XIB 2)将RoundRect按钮从Objects Library拖到这个XIB上 3)将XIB保存为“MyButton.xib”

这些步骤是否正确?下一步是什么?

【问题讨论】:

    标签: iphone interface-builder uibutton


    【解决方案1】:

    恕我直言,将您的 XIB 文件中的视图和 UIButton 连接到您的自定义 UIView-Class。

    然后为这个按钮创建点击方法并玩得开心:)

    【讨论】:

    • 如何加载 MyButton.xib?以及如何在加载后提取 UIButton?
    • 使用方法“initWithNibName”初始化您的 UIViewController 并设置您的 XIB 文件名。 UIViewController Reference 要使用 UIButton,您必须将 XIB 中的 Button 与您的 UIViewController 的属性连接起来。
    • 但是在我的应用程序中我没有任何 UIViewController。我只手动创建了 UIView。
    • 要显示一个 UIView,你需要一个 UIViewController,这个类有一个 UIView 类型的属性“view”。你有 iPhone 编程的经验吗?可能您从 beginner-tutorial? 开始
    • 要显示 UIView 我只需将它作为子视图添加到另一个(可见)视图。 UIViewController 中绝对不需要 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-02
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    相关资源
    最近更新 更多