【问题标题】:UITextField stroke attribute opaque in SwiftSwift中的UITextField笔画属性不透明
【发布时间】:2016-07-14 23:12:34
【问题描述】:

我在开发 Meme 应用程序时遇到了一个奇怪的问题。我正在尝试创建一个具有黑色轮廓和填充白色文本的 UITextField。我只能创建一个白色文本字段和另一个以黑色勾勒的文本字段,但是我不能同时获得两者。任何帮助将非常感激。

这是我分配给文本字段的属性:

让属性 = [ NSForegroundColorAttributeName: UIColor.whiteColor(), NSFontAttributeName: UIFont(name: "HelveticaNeue-CondensedBlack", size: 40)!, NSStrokeColorAttributeName: UIColor.blackColor(), NSStrokeWidthAttributeName:1.0 ]

应用如下所示:

【问题讨论】:

    标签: ios swift user-interface


    【解决方案1】:

    .strokeWidth = 0 产生没有描边的填充。

    .strokeWidth = positiveNumber 产生没有填充的描边。

    .strokeWidth = negativeNumber 同时生成描边和填充。

    【讨论】:

      【解决方案2】:

      Apple 有一个页面准确描述了您所面临的问题:Drawing attributed strings that are both filled and stroked。诀窍是将笔画宽度改为负数:

      斯威夫特 4:

      let attributes: [NSAttributedStringKey: Any] = [
          .foregroundColor: UIColor.white,
          .font: UIFont(name: "HelveticaNeue-CondensedBlack", size: 40)!,
          .strokeColor: UIColor.black,
          .strokeWidth: -1 // Change here
      ]
      

      斯威夫特 2:

      let attributes = [
          NSForegroundColorAttributeName: UIColor.whiteColor(),
          NSFontAttributeName: UIFont(name: "HelveticaNeue-CondensedBlack", size: 40)!,
          NSStrokeColorAttributeName: UIColor.blackColor(),
          NSStrokeWidthAttributeName: -1 // Change here
      ]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-08
        • 1970-01-01
        • 1970-01-01
        • 2014-08-14
        • 1970-01-01
        • 2021-11-12
        相关资源
        最近更新 更多