Skip to content

Commit

Permalink
feat: remove argument name for string input
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Bachant committed Sep 11, 2018
1 parent 71b3744 commit 84dc279
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -63,3 +63,4 @@ fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
.DS_Store
6 changes: 3 additions & 3 deletions InitialsImageView.podspec
@@ -1,15 +1,15 @@
Pod::Spec.new do |s|
s.name = "InitialsImageView"
s.version = "0.2.0"
s.version = "0.3.0"
s.summary = "A simple UIImageView extension for using initials as a profile image, written in swift"
s.description = "An easy, helpful UIImageView extension that generates letter initials as a placeholder for user profile images, with a randomized background color."
s.homepage = "https://github.com/bachonk/InitialsImageView"
s.screenshots = "http://i.imgur.com/xSBjVQ7.png"
s.screenshots = "https://i.imgur.com/KE8OfrL.png"
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { "Tom Bachant" => "tom@dashride.com" }
s.platform = :ios, '8.0'
s.source = { :git => "https://github.com/bachonk/InitialsImageView.git",
:tag => '0.2.0' }
:tag => '0.3.0' }
s.source_files = 'InitialsImageView.swift'
s.requires_arc = true
end
10 changes: 5 additions & 5 deletions InitialsImageView.swift
Expand Up @@ -20,17 +20,17 @@ let kGradientBotomOffset: HSVOffset = (hue: 0.025, saturation: -0.05, brightness

extension UIImageView {

public func setImageForName(string: String, backgroundColor: UIColor? = nil, circular: Bool, textAttributes: [NSAttributedStringKey: AnyObject]?, gradient: Bool = false) {
public func setImageForName(_ string: String, backgroundColor: UIColor? = nil, circular: Bool, textAttributes: [NSAttributedStringKey: AnyObject]?, gradient: Bool = false) {

setImageForName(string: string, backgroundColor: backgroundColor, circular: circular, textAttributes: textAttributes, gradient: gradient, gradientColors: nil)
setImageForName(string, backgroundColor: backgroundColor, circular: circular, textAttributes: textAttributes, gradient: gradient, gradientColors: nil)
}

public func setImageForName(string: String, gradientColors: GradientColors, circular: Bool, textAttributes: [NSAttributedStringKey: AnyObject]?) {
public func setImageForName(_ string: String, gradientColors: GradientColors, circular: Bool, textAttributes: [NSAttributedStringKey: AnyObject]?) {

setImageForName(string: string, backgroundColor: nil, circular: circular, textAttributes: textAttributes, gradient: true, gradientColors: gradientColors)
setImageForName(string, backgroundColor: nil, circular: circular, textAttributes: textAttributes, gradient: true, gradientColors: gradientColors)
}

private func setImageForName(string: String, backgroundColor: UIColor?, circular: Bool, textAttributes: [NSAttributedStringKey: AnyObject]?, gradient: Bool = false, gradientColors: GradientColors?) {
private func setImageForName(_ string: String, backgroundColor: UIColor?, circular: Bool, textAttributes: [NSAttributedStringKey: AnyObject]?, gradient: Bool = false, gradientColors: GradientColors?) {

let initials: String = initialsFromString(string: string)
let color: UIColor = (backgroundColor != nil) ? backgroundColor! : randomColor(for: string)
Expand Down
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Expand Up @@ -18,13 +18,13 @@ class ViewController: UIViewController {
let randomImage: UIImageView = UIImageView.init(frame: CGRect(x: self.view.bounds.midX - 40, y: self.view.bounds.midY - 80 - 40, width: 80, height: 80))
self.view.addSubview(randomImage)

randomImage.setImageForName(string: "Hello World", circular: true, textAttributes: nil, gradient: true)
randomImage.setImageForName("Hello World", circular: true, textAttributes: nil, gradient: true)

// More specific option with bg color and font specified
let customImage: UIImageView = UIImageView.init(frame: CGRect(x: self.view.bounds.midX - 40, y: self.view.bounds.midY + 40, width: 80, height: 80))
self.view.addSubview(customImage)

customImage.setImageForName(string: "Custom Font", backgroundColor: .blue, circular: true, textAttributes: [NSAttributedStringKey(rawValue: NSAttributedStringKey.font.rawValue): UIFont(name: "AmericanTypewriter-Bold", size: 30)!, NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.init(white: 1.0, alpha: 0.5)])
customImage.setImageForName("Custom Font", backgroundColor: .blue, circular: true, textAttributes: [NSAttributedStringKey(rawValue: NSAttributedStringKey.font.rawValue): UIFont(name: "AmericanTypewriter-Bold", size: 30)!, NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue): UIColor.init(white: 1.0, alpha: 0.5)])

}

Expand Down

0 comments on commit 84dc279

Please sign in to comment.