ampavatarview

About AMPAvatarView

AMPAvatarView is a powerful customizable library for iOS that allows you to easily display and customize user avatars in your app. With AMPAvatarView, you can add beautiful and dynamic avatars to enhance user profiles, chat applications, or any other feature that requires avatar representation.

Features

  • Create avatars with initials or images
  • Customize avatar shape, size, and border
  • Supports various image loading libraries
  • Apply gradient backgrounds to avatars
  • Add overlays and badges on avatars
  • Support for corner radius and oval avatars
  • Ability to cache images for improved performance
  • Easy handling of taps and long-press gestures
  • Full support for dark mode

Installation

To install AMPAvatarView in your iOS project, follow the steps below:

  1. Add the following line to your Podfile:

pod 'AMPAvatarView'

  1. Run the command pod install in the terminal.
  2. Open your project workspace or project file.
  3. Add import AMPAvatarView to the file where you want to use AMPAvatarView.

Usage

Create an AMPAvatarView programmatically

<!-- Creates an AMPAvatarView using initials -->

“`swift
let avatarView = AMPAvatarView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
avatarView.setInitials(“JD”)
view.addSubview(avatarView)
“`

<!-- Creates an AMPAvatarView using an image -->

“`swift
let avatarView = AMPAvatarView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
avatarView.setImage(“avatar.png”)
view.addSubview(avatarView)
“`

Customize AMPAvatarView appearance

<!-- Sets the avatar shape to square -->

“`swift
avatarView.avatarShape = .square
“`

<!-- Sets the avatar size to 80x80 -->

“`swift
avatarView.avatarSize = CGSize(width: 80, height: 80)
“`

<!-- Sets a border with a black color -->

“`swift
avatarView.setBorder(width: 2, color: .black)
“`

Advanced customization options

<!-- Apply a gradient background to the avatar -->

“`swift
let startColor = UIColor(red: 0.2, green: 0.4, blue: 0.8, alpha: 1.0)
let endColor = UIColor(red: 0, green: 0, blue: 0, alpha: 1.0)
avatarView.setGradientBackground(startColor: startColor, endColor: endColor)
“`

<!-- Add an overlay on the avatar -->

“`swift
avatarView.setOverlay(color: .red, alpha: 0.5)
“`

<!-- Add a badge indicating user status -->

“`swift
avatarView.addBadge(text: “Active”, backgroundColor: .green, textColor: .white)
“`

Additional Settings

Image caching

<!-- Enable image caching with default settings -->

“`swift
avatarView.enableImageCaching()
“`

<!-- Enable image caching with custom disk capacity and memory limit -->

“`swift
avatarView.enableImageCaching(diskCapacity: 100 * 1024 * 1024, memoryLimit: 50 * 1024 * 1024)
“`

Handling avatar gestures

<!-- Add a tap gesture recognizer to avatar -->

“`swift
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(avatarTapped))
avatarView.addGestureRecognizer(tapGesture)
“`

<!-- Handle tap gesture -->

“`swift
@objc func avatarTapped() {
print(“Avatar tapped!”)
}
“`

Dark Mode Support

AMPAvatarView provides full support for dark mode. Simply set the avatar colors according to your dark mode color scheme, and the library will automatically adjust the avatar appearance when the user switches between light and dark modes.

Further Documentation

For more detailed information and documentation, refer to the official GitHub repository of AMPAvatarView: https://github.com/ampwork/AMPAvatarView