【问题标题】:Creation of UIButton inside UITextfield在 UITextfield 内创建 UIButton
【发布时间】:2013-02-18 08:19:41
【问题描述】:

我是 ios 开发的新手。我想在 UITextfield 中创建 UIButton。当我们单击 UIButton Uidatepicker 出现时,当我们从 datepicker 中选择日期时,日期应该显示在 UitextFiels 中。我知道除了在 Uitextfield 中插入 UiButton 和 Giving 之外的所有逻辑对它采取行动。任何人都可以给我这个想法。

谢谢,提前

【问题讨论】:

  • 应该可以输入日期还是只能用日期选择器选择日期?在后一种情况下,fibnochi 给出了正确的答案。

标签: ios uibutton uitextfield


【解决方案1】:

您可以在不使用 UIButton 的情况下实现您的目标。为此使用 UITextField 的委托方法。 in- (BOOL)textFieldShouldBeginEditing:(UITextField *)textFieldreturn NO 并显示 datePikcer 当 datepicker 关闭时,设置 UITextFiled 的文本。供参考看看http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html

【讨论】:

    【解决方案2】:

    无需在 UItextfield 中插入 UIbutton。将 uibutton 放在 uitextfield 上。只是你需要为文本字段和按钮提供相同的框架,并将按钮设为自定义按钮。

    【讨论】:

      【解决方案3】:

      添加 UITextField 后添加 UIButton 实例。 UIButton 的框架应该在 UITextField 框架内。添加子视图时请记住,在添加 UITextField 之后添加 UIButton。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-07-24
        • 2017-10-15
        相关资源
        最近更新 更多