【问题标题】:How to hide UITextField border?如何隐藏 UITextField 边框?
【发布时间】:2013-11-21 09:03:59
【问题描述】:

我有一个 UITextField,我正在尝试使 UITextField 边框不可见,以便背景和 UITextField 具有相同的颜色并且会有无缝的外观。但问题是我也使用了占位符,并且有一个无法删除的边框。我已经试过了:

textOption.borderStyle = UITextBorderStyleNone;
textOption.layer.borderWidth = 0;

没有用。你能帮我解决这个问题吗?我仍然可以看到 UITextField 的边框。仅供参考:我使用的 UITextView 没有这个问题 => UITextViews 中没有占位符。

【问题讨论】:

  • 怎么样 textOption.backgroundColor = [UIColor clearColor]; ...

标签: xcode uikit uitextview border


【解决方案1】:

如果要删除文本框边框,可以直接使用界面生成器进行:

【讨论】:

  • 对我不起作用!它也可能是别的东西吗?谢谢!
【解决方案2】:

就用这个吧..

textOption.borderStyle = UITextBorderStyleNone;
[textOption setBackgroundColor:[UIColor clearColor]];

【讨论】:

    【解决方案3】:

    斯威夫特 4 和 5:

    yourTextfield.borderStyle = .none
    

    【讨论】:

      【解决方案4】:

      在 Swift 中,这对我有用:

       passwordTextField.borderStyle = UITextBorderStyle.none
      

      【讨论】:

        【解决方案5】:

        如果您使用的是 Interface Builder 或 Storyboard,您可以选择 textField,进入属性检查器选项卡,在选项边框样式下,您有 4 种样式可供选择,第一个是无边框的。

        如果在代码中这样做,这应该可以工作

        textOption.borderStyle = UITextBorderStyleNone;
        [textOption setBackgroundColor:[UIColor clearColor]];
        

        【讨论】:

          【解决方案6】:

          你只需要设置边框样式无

           textFieldName.borderStyle = UITextBorderStyleNone;
          

          【讨论】:

            【解决方案7】:
            UITextField *tfText = [[UITextField alloc] initWithFrame:CGRectMake(65, 200, 200, 30)];
                tfText.backgroundColor = [UIColor colorWithRed:0.2 green:0.9 blue:0.5 alpha:0.3];       
                tfText.textAlignment = UITextAlignmentCenter;
                // Border Style None
                [tfText setBorderStyle:UITextBorderStyleNone];
                [self.view addSubview:tfText];
                [tfText release];
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 2012-06-18
              • 1970-01-01
              • 1970-01-01
              • 2016-03-07
              • 1970-01-01
              • 1970-01-01
              • 2011-09-28
              • 1970-01-01
              相关资源
              最近更新 更多