In swift 2.0 this can be done as follows
//Defining fonts of size and type
let firstfont:UIFont = UIFont(name: "Helvetica Neue", size: 17)!
let boldFont:UIFont = UIFont(name: "HelveticaNeue-Bold", size: 17)!
let thirdFont:UIFont = UIFont(name: "HelveticaNeue-ThinItalic", size: 17)!
//Making dictionaries of fonts that will be passed as an attribute
let firstDict:NSDictionary = NSDictionary(object: firstfont, forKey:
NSFontAttributeName)
let boldDict:NSDictionary = NSDictionary(object: boldFont, forKey:
NSFontAttributeName)
let thirdDict:NSDictionary = NSDictionary(object: thirdFont, forKey:
NSFontAttributeName)
let firstText = "My name is "
let attributedString = NSMutableAttributedString(string: firstText,
attributes: firstDict as? [String : AnyObject])
let boldText = "Rajan"
let boldString = NSMutableAttributedString(string:boldText,
attributes:boldDict as? [String : AnyObject])
let finalText = " iOS"
let finalAttributedString = NSMutableAttributedString(string:
finalText, attributes: thirdDict as? [String : AnyObject])
attributedString.appendAttributedString(boldString)
attributedString.appendAttributedString(finalAttributedString)
myLabel.attributedText = attributedString
Edit
Swift 3.0
let firstfont:UIFont = UIFont(name: "Helvetica Neue", size: 17)!
let boldFont:UIFont = UIFont(name: "HelveticaNeue-Bold", size: 17)!
let thirdFont:UIFont = UIFont(name: "HelveticaNeue-ThinItalic", size: 17)!
//Making dictionaries of fonts that will be passed as an attribute
let firstDict:NSDictionary = NSDictionary(object: firstfont, forKey:
NSFontAttributeName as NSCopying)
let boldDict:NSDictionary = NSDictionary(object: boldFont, forKey:
NSFontAttributeName as NSCopying)
let thirdDict:NSDictionary = NSDictionary(object: thirdFont, forKey:
NSFontAttributeName as NSCopying)
let firstText = "My name is "
let attributedString = NSMutableAttributedString(string: firstText,
attributes: firstDict as? [String : AnyObject])
let boldText = "Rajan"
let boldString = NSMutableAttributedString(string:boldText,
attributes:boldDict as? [String : AnyObject])
let finalText = " iOS"
let finalAttributedString = NSMutableAttributedString(string:
finalText, attributes: thirdDict as? [String : AnyObject])
attributedString.append(boldString)
attributedString.append(finalAttributedString)
myLabel.attributedText = attributedString
Edit
Swift 4.0
let firstfont:UIFont = UIFont(name: "Helvetica Neue", size: 17)!
let boldFont:UIFont = UIFont(name: "HelveticaNeue-Bold", size: 17)!
let thirdFont:UIFont = UIFont(name: "HelveticaNeue-ThinItalic", size: 17)!
//Making dictionaries of fonts that will be passed as an attribute
let firstDict:NSDictionary = NSDictionary(object: firstfont, forKey:
NSAttributedString.Key.font as NSCopying)
let boldDict:NSDictionary = NSDictionary(object: boldFont, forKey:
NSAttributedString.Key.font as NSCopying)
let thirdDict:NSDictionary = NSDictionary(object: thirdFont, forKey:
NSAttributedString.Key.font as NSCopying)
let firstText = "My name is "
let attributedString = NSMutableAttributedString(string: firstText,
attributes: firstDict as? [NSAttributedString.Key : Any])
let boldText = "Rajan"
let boldString = NSMutableAttributedString(string:boldText,
attributes:boldDict as? [NSAttributedString.Key : Any])
let finalText = " iOS"
let finalAttributedString = NSMutableAttributedString(string:
finalText, attributes: thirdDict as? [NSAttributedString.Key : Any])
attributedString.append(boldString)
attributedString.append(finalAttributedString)
myLabel.attributedText = attributedString
This will look like