【问题标题】:UITextField w/ drop down button带有下拉按钮的 UITextField
【发布时间】:2014-11-18 15:16:07
【问题描述】:

UITextField 可以单独使用代码来完成此 UI,还是我需要为此使用图像或使用其他组件?比如按钮、标签。

【问题讨论】:

    标签: ios uibutton uitextfield


    【解决方案1】:

    你可以通过使用UITextFieldUIButtonUITableView和一些动画来实现这一点,无论如何一旦看看这个例子ios dropdown

    【讨论】:

    • 我不需要用于下拉列表的表格视图,我只需要 UI,但谢谢。
    • 做你喜欢的事...:)
    【解决方案2】:

    UITextField 不提供这种功能。您需要使用UIImageView、UIButton 和UITextField,在UIImageView 中设置包含您的文本字段背景图像的图像,禁用文本字段的 UserInteraction 属性并将其保留在 imageView 上,使用没有标题的自定义按钮并执行您想要的带有按钮的操作。

    【讨论】:

      【解决方案3】:

      试试这个。

      UIImageView *imgViewForDropDown = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
      imgViewForDropDown.image = [UIImage imageNamed:@"dropDown.png"];
      yourTextField.rightView = imgViewForDropDown;
      yourTextField.rightViewMode = UITextFieldViewModeAlways;
      

      对于 Swift 代码:

      let imgViewForDropDown = UIImageView()
      imgViewForDropDown.frame = CGRect(x: 0, y: 0, width: 30, height: 48)
      imgViewForDropDown.image = UIImage(named: "ic_keyboard_arrow_down_white")
      yourTextField.rightView = imgViewForDropDown
      yourTextField.rightViewMode = .always
      

      【讨论】:

        【解决方案4】:

        这行得通:

            fileprivate func addBtnToTextField() {
        
            let dropDownBtn = UIButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
            dropDownBtn.setBackgroundImage(UIImage(named: "dropDownTringle"), for: UIControlState.normal)
            startDateTxt.rightViewMode = UITextFieldViewMode.always
            startDateTxt.rightView = dropDownBtn
        
        }
        

        【讨论】:

          猜你喜欢
          • 2017-10-11
          • 1970-01-01
          • 2020-12-29
          • 2013-07-06
          • 2018-07-27
          • 2014-11-20
          • 2021-01-19
          • 2011-03-25
          • 1970-01-01
          相关资源
          最近更新 更多