【问题标题】:NativeScript <TextField> with only a bottom border on iOSNativeScript <TextField> 在 iOS 上只有一个底部边框
【发布时间】:2016-03-11 21:08:22
【问题描述】:

我正在尝试创建一个 NativeScript &lt;TextField&gt;,它在控件下方只有一个边框。有几个 Stack Overflow 问题通常可以解决 UITextFields 的这个问题(例如 How to only show bottom border of UITextField in Swift),但是无论出于何种原因,这些相同的技术似乎不适用于 NativeScript &lt;TextField&gt;s。

例如,我希望这段代码可以工作:

<!-- my-page.xml -->
<TextField id="email" />

/* my-page.js */
var myTextField = page.getViewById("email").ios;
var bottomLine = new CALayer();
bottomLine.frame = CGRectMake(1, 50, 50, 1);
bottomLine.backgroundColor = UIColor.whiteColor().CGColor;
myTextField.borderStyle = UITextBorderStyle.None;
myTextField.layer.addSublayer(bottomLine);

...但没有绘制边框。

我不确定是我做错了什么,还是像 {N} 的 CSS 实现这样的东西覆盖了我的更改。任何帮助将不胜感激。

谢谢!

【问题讨论】:

    标签: ios textfield nativescript


    【解决方案1】:

    添加以下代码:

    let width = CGFloat(1.0);
    bottomLine.frame = CGRect(x: 0, y: myTextField.frame.size.height - width, width:  myTextField.frame.size.width, height: myTextField.frame.size.height);
    bottomLine.backgroundColor = UIColor.whiteColor().CGColor;
    myTextField.borderStyle = UITextBorderStyle.None;
    myTextField.layer.addSublayer(bottomLine);
    

    【讨论】:

      猜你喜欢
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-21
      • 1970-01-01
      • 1970-01-01
      • 2017-04-15
      • 1970-01-01
      相关资源
      最近更新 更多