Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bachonk/InitialsImageView
A simple UIImageView extension for using initials as a profile image, written in swift
https://github.com/bachonk/InitialsImageView
Last synced: 7 days ago
JSON representation
A simple UIImageView extension for using initials as a profile image, written in swift
- Host: GitHub
- URL: https://github.com/bachonk/InitialsImageView
- Owner: bachonk
- License: mit
- Created: 2017-03-25T21:32:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-08-07T16:19:18.000Z (over 2 years ago)
- Last Synced: 2024-04-24T19:02:00.569Z (8 months ago)
- Language: Swift
- Size: 29.3 KB
- Stars: 213
- Watchers: 12
- Forks: 41
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ios - InitialsImageView - An UIImageView extension that generates letter initials as a placeholder for user profile images, with a randomized background color. (Media / Image)
- awesome-cocoa - InitialsImageView
- awesome-ios-star - InitialsImageView - An UIImageView extension that generates letter initials as a placeholder for user profile images, with a randomized background color. (Media / Image)
README
InitialsImageView
===================An easy, helpful UIImageView extension that generates letter initials as a placeholder for user profile images, with a randomized background color
![Example screenshot](https://i.imgur.com/KE8OfrL.png)
### Installation
##### CocoaPods
Add this spec to your podfile:
`pod "InitialsImageView"`
Check out the [official guide](http://guides.cocoapods.org/using/index.html) for getting started with CocoaPods.
##### Swift Package Manager
You can use the [Swift Package Manager](https://swift.org/package-manager/) to install `InitialsImageView` by adding it to the `dependencies` value of your `Package.swift`:
```swift
dependencies: [
.package(url: "https://github.com/bachonk/InitialsImageView.git", .upToNextMajor(from: "0.0.0"))
]
```##### Manual
1. Drag the `InitialsImageView.swift` file into your project
2. Enjoy!### Usage
##### Methods
Call the following methods on any `UIImageView` instance to set the image:
+ `setImageForName(string: String, backgroundColor: UIColor?, circular: Bool, textAttributes: [String: AnyObject]?)`
`string` is the string used to generate the initials. This should be a user's full name if available.
`backgroundColor` is an optional parameter that sets the background color of the image. Pass in `nil` to have a color automatically generated for you.
`circular` is a boolean parameter that will automatically clip the image to a circle if enabled.
`textAttributes` is an optional dictionary of predefined character attributes for text. You can find the list of available keys in NSAttributedString
##### Example
```
let randomImage: UIImageView = UIImageView.init(frame: CGRect(x: self.view.bounds.midX - 40, y: self.view.bounds.midY - 80 - 40, width: 80, height: 80))
randomImage.setImageForName(string: "Michael Bluth", backgroundColor: nil, circular: true, textAttributes: nil)
```### Saying Thanks
If you like this tool, show your support by downloading the free [Turnout](https://itunes.apple.com/us/app/turnout-make-plans-w-friends/id1393733205?mt=8) app that inspired it!
### License
Using the MIT license. See license file for details.