在SWIFT中向UILabel文本添加笔划

时间:2015-05-07 19:26:06

标签: swift nsstring

我正在尝试在Swift中为UILabel文本添加笔划。这是我用过的文字:

var congratsLabel = UILabel(frame: CGRectMake(10, popUpView.frame.size.height * 0.540, popUpView.frame.size.width, 70))
congratsLabel.font = UIFont(name: Font.Daydreamer, size: 70)
congratsLabel.text = "Snap!"
congratsLabel.numberOfLines = 0
congratsLabel.textColor = UIColor.whiteColor()
congratsLabel.textAlignment = NSTextAlignment.Center
popUpView.addSubview(congratsLabel)

我也试过使用NSMutableAttributedString虽然它有点啰嗦而不是我想要的,我用的代码也是:

var String = "Snap!"

var strokeString = NSMutableAttributedString(string: String, attributes: [NSFontAttributeName:UIFont(name: Font.Daydreamer, size: 70.0)!])
strokeString.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor(), range: NSRange(location:0,length:5))
strokeString.addAttribute(NSStrokeColorAttributeName, value: UIColor.blackColor(), range:  NSRange(location: 0, length: 5))
strokeString.addAttribute(NSStrokeWidthAttributeName, value: 1, range: NSRange(location: 0, length: 5))

这是我试图重新创建的外观。

enter image description here

但它会像这样出现(背景不同),但正如你所看到的那样,笔画正在接管整个单词:

enter image description here

0 个答案:

没有答案