Chatto icon indicating copy to clipboard operation
Chatto copied to clipboard

Circle User Avatar

Open starsoheil2007 opened this issue 8 years ago • 8 comments

I Install Chatto with Pods : pod 'Chatto', '~> 3.0.1' pod 'ChattoAdditions', '~> 3.0.1'

I need UserAvatar imageview show circle ? Witch class must be override ? Thanks

starsoheil2007 avatar Jan 07 '17 12:01 starsoheil2007

I also need circle avatarView. How to access to avatarView when using your ChattoAdditions?

d-date avatar Mar 01 '17 04:03 d-date

I don't know if it's the right place but modifying layoutSubViews() in BaseMessageCollectionViewCell.swift with:

self.avatarView.layer.cornerRadius = self.avatarView.frame.size.width / 2
self.avatarView.clipsToBounds = true

below the self.avatarView.bma_rect = layoutModel.avatarViewFrame line, works.

lukeleleh avatar Mar 01 '17 12:03 lukeleleh

A hack that we've come up with in our project is to render a new UIImage with rounded edges and use that as the avatar image. However, we'd prefer to have a proper solution where it's possible to set the cornerRadius on the UIImageView

extension UIImage {
    
    func createRoundedImage() -> UIImage {
        let imageLayer = CALayer()
        imageLayer.frame = CGRect(x: 0.0, y: 0.0, w: self.size.width, h: self.size.height)
        imageLayer.contents = self.cgImage
        
        imageLayer.masksToBounds = true
        imageLayer.cornerRadius = self.size.width / 2
        
        UIGraphicsBeginImageContext(self.size)
        imageLayer.render(in: UIGraphicsGetCurrentContext()!)
        
        let roundedImage = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        
        return roundedImage!
    }
    
}

Kumuluzz avatar Mar 01 '17 12:03 Kumuluzz

I agree with @LukA888 , then we need to add property like avatarStyle on BaseMessageViewModel, and able to use like below.

viewModel.avatarStyle = .circle
viewModel.avatarStyle = .square

enum AvatarStyle {
  case .circle
  case .square
}

So, I'll start to make PR for Chatto.

d-date avatar Mar 06 '17 06:03 d-date

Hi @d-date ! Have you done PR for this rounding?

alexanderkhitev avatar Jul 10 '17 14:07 alexanderkhitev

@alexsanderkhitev Afraid not, but I found that we shouldn't customize cells using this repo. I think this repo is needed for easy to construct chat UI, without customizability. so try to consider to create your own cell:)

d-date avatar Jul 11 '17 00:07 d-date

@d-date thank you for response!

alexanderkhitev avatar Jul 12 '17 06:07 alexanderkhitev

Any news in new release about circle avatar?

Denismih avatar May 29 '20 12:05 Denismih