UITextView contenir des caractères Gras et Régulier de la chaîne

Je voudrais ajouter une corde à mon UITextView et j'aimerais que certains en caractères gras et certains caractères normaux. Comment faut-Il faire? J'ai un exemple de ce que je voudrais ci-dessous.

Grâce

myTextView.text = "This is my string. "

Ce est mon chaîne.

Ci-dessous les tentatives que j'ai faites.

    //Define string attributes
    let font = UIFont(name: "Georgia", size: 18.0) ?? UIFont.systemFontOfSize(18.0)
    let textFont = [NSFontAttributeName:font]

    let fontItal = UIFont(name: "Georgia-Italic", size: 40.0) ?? UIFont.systemFontOfSize(40.0)
    let italFont = [NSFontAttributeName:fontItal]

    //Create a string that will be our paragraph
    let para = NSMutableAttributedString()

    //Create locally formatted strings
    let attrString1 = NSAttributedString(string: "This is ", attributes:textFont)
    let attrString2 = NSAttributedString(string: "my", attributes:italFont)
    let attrString3 = NSAttributedString(string: " string.", attributes:textFont)

    //Add locally formatted strings to paragraph
    para.appendAttributedString(attrString1)
    para.appendAttributedString(attrString2)
    para.appendAttributedString(attrString3)

    //Define paragraph styling
    let paraStyle = NSMutableParagraphStyle()
    paraStyle.firstLineHeadIndent = 15.0
    paraStyle.paragraphSpacingBefore = 10.0

    //Apply paragraph styles to paragraph
    para.addAttribute(NSParagraphStyleAttributeName, value: paraStyle, range: NSRange(location: 0,length: para.length))


    //Add string to UITextView

    myTextView.attributedText = para
S'il vous plaît montrer les tentatives que vous avez déjà fait pour résoudre le problème.
Ajouté le code ci-dessus. Merci
Bon, et comment les résultats que vous recevez de différer de ce que vous attendez?
Le texte ne change pas. Il affiche la chaîne de caractères dans la police par défaut (helvetica) sans italique.

OriginalL'auteur Tom Coomer | 2014-12-29