From e7bc2e86db63ec38febfa5fbb112b7cc97a6ecc2 Mon Sep 17 00:00:00 2001 From: Michael Kirk Date: Fri, 9 Dec 2016 14:19:18 -0500 Subject: [PATCH] Show email as name when contact has no name // FREEBIE --- Signal/src/views/ContactCell.swift | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Signal/src/views/ContactCell.swift b/Signal/src/views/ContactCell.swift index 9d7486ddf..6fdb4db91 100644 --- a/Signal/src/views/ContactCell.swift +++ b/Signal/src/views/ContactCell.swift @@ -99,20 +99,25 @@ fileprivate extension CNContact { func formattedFullName(font: UIFont) -> NSAttributedString? { let keyToHighlight = ContactSortOrder == .familyName ? CNContactFamilyNameKey : CNContactGivenNameKey + let boldDescriptor = font.fontDescriptor.withSymbolicTraits(.traitBold) + let boldAttributes = [ + NSFontAttributeName: UIFont(descriptor:boldDescriptor!, size: 0) + ] + if let attributedName = CNContactFormatter.attributedString(from: self, style: .fullName, defaultAttributes: nil) { let highlightedName = attributedName.mutableCopy() as! NSMutableAttributedString highlightedName.enumerateAttributes(in: NSMakeRange(0, highlightedName.length), options: [], using: { (attrs, range, stop) in if let property = attrs[CNContactPropertyAttribute] as? String, property == keyToHighlight { - let boldDescriptor = font.fontDescriptor.withSymbolicTraits(.traitBold) - let boldAttributes = [ - NSFontAttributeName: UIFont(descriptor:boldDescriptor!, size: 0) - ] - highlightedName.addAttributes(boldAttributes, range: range) } }) return highlightedName } + + if let emailAddress = (self.emailAddresses.first?.value as String?) { + return NSAttributedString(string: emailAddress, attributes: boldAttributes) + } + return nil } }