|
@@ -16,6 +16,11 @@ class InitialsBadge: UIView {
|
|
setColor(color)
|
|
setColor(color)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ convenience init (image: UIImage, size: CGFloat) {
|
|
|
|
+ self.init(size: size)
|
|
|
|
+ setImage(image)
|
|
|
|
+ }
|
|
|
|
+
|
|
init(size: CGFloat) {
|
|
init(size: CGFloat) {
|
|
super.init(frame: CGRect(x: 0, y: 0, width: size, height: size))
|
|
super.init(frame: CGRect(x: 0, y: 0, width: size, height: size))
|
|
let initialsLabelCornerRadius = size / 2
|
|
let initialsLabelCornerRadius = size / 2
|
|
@@ -30,9 +35,9 @@ class InitialsBadge: UIView {
|
|
private func setupSubviews() {
|
|
private func setupSubviews() {
|
|
addSubview(label)
|
|
addSubview(label)
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
label.translatesAutoresizingMaskIntoConstraints = false
|
|
- label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 2).isActive = true
|
|
|
|
- label.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -2).isActive = true
|
|
|
|
- label.centerYAnchor.constraint(equalTo: centerYAnchor, constant: 0).isActive = true
|
|
|
|
|
|
+ label.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
|
|
|
+ label.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
|
|
|
+ label.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
|
|
}
|
|
}
|
|
|
|
|
|
required init?(coder _: NSCoder) {
|
|
required init?(coder _: NSCoder) {
|
|
@@ -43,6 +48,14 @@ class InitialsBadge: UIView {
|
|
label.text = Utils.getInitials(inputName: name)
|
|
label.text = Utils.getInitials(inputName: name)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ func setImage(_ image: UIImage) {
|
|
|
|
+ if let resizedImg = image.resizeImage(targetSize: CGSize(width: self.frame.width, height: self.frame.height)) {
|
|
|
|
+ let attachment = NSTextAttachment()
|
|
|
|
+ attachment.image = resizedImg
|
|
|
|
+ label.attributedText = NSAttributedString(attachment: attachment)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
func setColor(_ color: UIColor) {
|
|
func setColor(_ color: UIColor) {
|
|
backgroundColor = color
|
|
backgroundColor = color
|
|
}
|
|
}
|