不需要go attributedText,老实说,这是一个混乱的实施修改间距.我一合上键盘,空格就消失了,这促使我进一步挖掘.
每个UITextField都有一个名为defaultTextAttributes的属性,根据Apple "returns a dictionary of text attributes with default values."的说法.Apple document人也表示"this property applies the specified attributes to the entire text of the text field"人
只需在代码中找到一个合适的地方,通常是文本字段被初始化的地方,然后复制并粘贴以下内容.
用Swift 3.0回答
textfield.defaultTextAttributes.updateValue(spacing, forKey: NSKernAttributeName)
其中间距为CGFloat类型.例如2.0
这也适用于不同的字体.
干杯
最新的语法似乎是:
yourField.defaultTextAttributes.updateValue(36.0,
forKey: NSAttributedString.Key.kern)