0

I have two attributed strings and I want to place them in one label, how would I do this?

let font = UIFont(name: "Hidden", size: 15)
    let addfont = UIFont(name: "Hidden", size: 15)
    var att = [NSFontAttributeName : font]
    let attrString = NSAttributedString(
        string: animalname[indexPath.row],
        attributes: NSDictionary(
            object: font!,
            forKey: NSFontAttributeName) as! [String : AnyObject])

    let attrStringAdd = NSAttributedString(
        string: animalloc[indexPath.row],
        attributes: NSDictionary(
            object: addfont!,
            forKey: NSFontAttributeName) as! [String : AnyObject])

    cell.animaltext.attributedText = attrString + attrStringAdd
fatihyildizhan
  • 8,614
  • 7
  • 64
  • 88
user6032625
  • 197
  • 1
  • 2
  • 14
  • 7
    Possible duplicate of [How can I concatenate NSAttributedStrings?](http://stackoverflow.com/questions/18518222/how-can-i-concatenate-nsattributedstrings) – juanjo Apr 07 '16 at 17:23

1 Answers1

1
  1. Concatinated both the string.
  2. Find range for string1 and string2.
  3. Then for particular range of string apply desired attribute.
  4. Now assign this attributed string to UILabel.
user3300864
  • 150
  • 7