Здесь я попытался добавить две UILabel
строки в одном UILabel
но я допустил некоторую ошибку, чтобы любой мог найти мою ошибку, пожалуйста?
let textFontAttributes = [
NSFontAttributeName : font,
// Note: SKColor.whiteColor().CGColor breaks this
NSForegroundColorAttributeName: UIColor.whiteColor(),
NSStrokeColorAttributeName: UIColor.blackColor(),
// Note: Use negative value here if you want foreground color to show
NSStrokeWidthAttributeName: -8]
Это демонстрация, вы можете попробовать. На самом деле вам следует предоставить больше информации о том, что случилось или что такое ошибка.
var firstString = "Hello" as NSString
var secondString = " World" as NSString
var totalString = firstString.stringByAppendingString(secondString as String) as NSString
let firsttAttributes = [
NSFontAttributeName : UIFont.systemFontOfSize(16),
// Note: SKColor.whiteColor().CGColor breaks this
NSForegroundColorAttributeName: UIColor.whiteColor(),
NSStrokeColorAttributeName: UIColor.blackColor(),
// Note: Use negative value here if you want foreground color to show
NSStrokeWidthAttributeName: -8]
let secondAttributes = [
NSFontAttributeName : UIFont.systemFontOfSize(12),
// Note: SKColor.whiteColor().CGColor breaks this
NSForegroundColorAttributeName: UIColor.redColor(),
NSStrokeColorAttributeName: UIColor.blackColor(),
// Note: Use negative value here if you want foreground color to show
NSStrokeWidthAttributeName: -8]
var attributedString = NSMutableAttributedString(string: totalString as String, attributes: firsttAttributes)
var secondRange = totalString.rangeOfString(secondString as String)
if secondRange.location != NSNotFound {
attributedString.addAttributes(secondAttributes, range: secondRange)
}