mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Show email as name when contact has no name
// FREEBIE
This commit is contained in:
parent
76d01863db
commit
e7bc2e86db
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue