Ios 如何附加两个具有不同字体的属性字符串?

Ios 如何附加两个具有不同字体的属性字符串?,ios,swift,fonts,uikit,nsattributedstring,Ios,Swift,Fonts,Uikit,Nsattributedstring,在这里,我试图在一个UILabel中附加两个属性字符串,但我犯了一些错误,所以任何人都可以找到我的错误,请 let textFontAttributes = [ NSFontAttributeName : font, // Note: SKColor.whiteColor().CGColor breaks this NSForegroundColorAttributeName: UIColor.whiteColor(),

在这里,我试图在一个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)
}

你能提供更多的错误信息吗?或者你犯了什么错误?我这边没有任何错误