【问题标题】:how to add style to label for show a string in swift如何为标签添加样式以快速显示字符串
【发布时间】:2018-12-19 12:48:37
【问题描述】:

我想在标签中使用样式编号。如下图所示。 但我没有这个想法。

sample image

【问题讨论】:

  • 基本的NSAttributedString 无法做到这一点。您可能需要使用 CoreText,并在 Photoshop(或任何其他高级图像应用程序)上“快速”完成大量效果,而不是通过编程完成。
  • 还有它的拼写“恭喜”

标签: ios swift fonts label nsattributedstring


【解决方案1】:
func textField(textField: UITextField, shouldChangeCharactersInRange range: NSRange, replacementString string: String) -> Bool {

  let aSet = NSCharacterSet(charactersInString:"0123456789").invertedSet
  let compSepByCharInSet = string.componentsSeparatedByCharactersInSet(aSet)
  let numberFiltered = compSepByCharInSet.joinWithSeparator("")
  return string == numberFiltered

}

【讨论】:

  • 我不太明白,但也许你可以用这个
猜你喜欢
  • 2016-11-27
  • 2011-07-12
  • 1970-01-01
  • 1970-01-01
  • 2011-05-15
  • 1970-01-01
  • 1970-01-01
  • 2014-07-09
  • 2013-01-29
相关资源
最近更新 更多