mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Updated the profile icon to default to using two characters (initials if possible)
This commit is contained in:
parent
b3d18b0135
commit
e786102f03
2 changed files with 11 additions and 2 deletions
|
@ -8,7 +8,17 @@ public final class Identicon : NSObject {
|
|||
if content.count > 2 && content.hasPrefix("05") {
|
||||
content.removeFirst(2)
|
||||
}
|
||||
let layer = icon.generateLayer(with: size, text: content.substring(to: 1))
|
||||
let initials: String = content
|
||||
.split(separator: " ")
|
||||
.compactMap { word in word.first.map { String($0) } }
|
||||
.joined()
|
||||
let layer = icon.generateLayer(
|
||||
with: size,
|
||||
text: (initials.count >= 2 ?
|
||||
initials.substring(to: 2).uppercased() :
|
||||
content.substring(to: 2).capitalized
|
||||
)
|
||||
)
|
||||
let rect = CGRect(origin: CGPoint.zero, size: layer.frame.size)
|
||||
let renderer = UIGraphicsImageRenderer(size: rect.size)
|
||||
return renderer.image { layer.render(in: $0.cgContext) }
|
||||
|
|
|
@ -37,7 +37,6 @@ public class PlaceholderIcon {
|
|||
}
|
||||
|
||||
private func getTextLayer(with diameter: CGFloat, colour: CGColor? = nil, text: String) -> CALayer {
|
||||
let text = text.capitalized
|
||||
let font = UIFont.boldSystemFont(ofSize: diameter / 2)
|
||||
let height = NSString(string: text).boundingRect(with: CGSize(width: diameter, height: CGFloat.greatestFiniteMagnitude),
|
||||
options: .usesLineFragmentOrigin, attributes: [ NSAttributedString.Key.font : font ], context: nil).height
|
||||
|
|
Loading…
Reference in a new issue