From dd3cf8a22197c6cddaa287f3248a13ad405048d6 Mon Sep 17 00:00:00 2001 From: Saurabh Rane Date: Wed, 5 Apr 2017 10:30:21 -0500 Subject: [PATCH] Readying for 1.1 --- README.md | 10 +- Source/SwiftIcons.swift | 104 ++++++++++++++++++ SwiftIcons.podspec | 2 +- SwiftIcons/Base.lproj/Main.storyboard | 2 +- SwiftIcons/ObjectsDetailsViewController.swift | 16 ++- docs/images/pic01.png | Bin 97909 -> 97109 bytes 6 files changed, 128 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 31ba443..f2b9241 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Add the following lines to your `Podfile`: ```ruby target 'YourProject' do use_frameworks! - pod 'SwiftIcons', '~> 1.0.2' + pod 'SwiftIcons', '~> 1.1' end ``` @@ -101,7 +101,7 @@ Check to import all ttf files in project, "Project" > "Target" > "Copy Bundle Re ## Library Reference -You can check library reference documentation [here](http://cocoadocs.org/docsets/SwiftIcons/1.0.2/). +You can check library reference documentation [here](http://cocoadocs.org/docsets/SwiftIcons/1.1/). ## Usage @@ -208,6 +208,12 @@ button.setIcon(prefixText: "Happy ", prefixTextFont: font1!, icon: .ionicons(.ha // Icon with text with different fonts & colors around it button.setIcon(prefixText: "Pulse ", prefixTextFont: font1!, prefixTextColor: .darkGray, icon: .openIconic(.pulse), iconColor: .red, postfixText: " icon", postfixTextFont: font2!, postfixTextColor: .purple, forState: .normal, iconSize: 40) +// Icon with title below icon +button.setIcon(icon: .emoji(.ferrisWheel), title: "Ferris Wheel", color: .red, forState: .normal) + +// Icon with title below icon with different color & custom font +button8.setIcon(icon: .weather(.rainMix), iconColor: .yellow, title: "RAIN MIX", titleColor: .red, font: font!, backgroundColor: .clear, borderSize: 1, borderColor: .green, forState: .normal) + ``` diff --git a/Source/SwiftIcons.swift b/Source/SwiftIcons.swift index 790e686..58e4990 100644 --- a/Source/SwiftIcons.swift +++ b/Source/SwiftIcons.swift @@ -372,6 +372,110 @@ public extension UIButton { setAttributedTitle(prefixTextAttribured, for: state) self.backgroundColor = backgroundColor } + + + /** + This function sets the icon to UIButton with title below it, with different colors + + - Parameter icon: The icon + - Parameter iconColor: Color for the icon + - Parameter title: The title + - Parameter titleColor: Color for the title + - Parameter backgroundColor: Background color for the button + - Parameter borderSize: Border size for the button + - Parameter borderColor: Border color for the button + - Parameter forState: Control state of the UIButton + + - Version: 1.1 + */ + public func setIcon(icon: FontType, iconColor: UIColor = .black, title: String, titleColor: UIColor = .black, backgroundColor: UIColor = .clear, borderSize: CGFloat = 1, borderColor: UIColor = .clear, forState state: UIControlState) { + + let height = frame.size.height + let width = frame.size.width + let gap : CGFloat = 5 + let textHeight : CGFloat = 15 + + let size1 = width - (borderSize * 2 + gap * 2) + let size2 = height - (borderSize * 2 + gap * 3 + textHeight) + let imageOrigin : CGFloat = borderSize + gap + let textTop : CGFloat = imageOrigin + size2 + gap + let textBottom : CGFloat = borderSize + gap + let imageBottom : CGFloat = textBottom + textHeight + gap + + let image = UIImage.init(icon: icon, size: CGSize(width: size1, height: size2), textColor: iconColor, backgroundColor: backgroundColor) + imageEdgeInsets = UIEdgeInsets(top: imageOrigin, left: imageOrigin, bottom: imageBottom, right: imageOrigin) + titleEdgeInsets = UIEdgeInsets(top: textTop, left: -image.size.width, bottom: textBottom, right: 0.0) + + layer.borderColor = borderColor.cgColor + layer.borderWidth = borderSize + setImage(image, for: state) + titleLabel?.adjustsFontSizeToFitWidth = true + titleLabel?.minimumScaleFactor = 0.1 + setTitle(title, for: state) + setTitleColor(titleColor, for: state) + self.backgroundColor = backgroundColor + } + + + /** + This function sets the icon to UIButton with title (custom font) below it, with different colors + + - Parameter icon: The icon + - Parameter iconColor: Color for the icon + - Parameter title: The title + - Parameter titleColor: Color for the title + - Parameter font: The font for the title below the icon + - Parameter backgroundColor: Background color for the button + - Parameter borderSize: Border size for the button + - Parameter borderColor: Border color for the button + - Parameter forState: Control state of the UIButton + + - Version: 1.1 + */ + public func setIcon(icon: FontType, iconColor: UIColor = .black, title: String, titleColor: UIColor = .black, font: UIFont, backgroundColor: UIColor = .clear, borderSize: CGFloat = 1, borderColor: UIColor = .clear, forState state: UIControlState) { + + setIcon(icon: icon, iconColor: iconColor, title: title, titleColor: titleColor, backgroundColor: backgroundColor, borderSize: borderSize, borderColor: borderColor, forState: state) + titleLabel?.font = font + } + + + /** + This function sets the icon to UIButton with title below it + + - Parameter icon: The icon + - Parameter title: The title + - Parameter color: Color for the icon & title + - Parameter backgroundColor: Background color for the button + - Parameter borderSize: Border size for the button + - Parameter borderColor: Border color for the button + - Parameter forState: Control state of the UIButton + + - Version: 1.1 + */ + public func setIcon(icon: FontType, title: String, color: UIColor = .black, backgroundColor: UIColor = .clear, borderSize: CGFloat = 1, borderColor: UIColor = .clear, forState state: UIControlState) { + + setIcon(icon: icon, iconColor: color, title: title, titleColor: color, backgroundColor: backgroundColor, borderSize: borderSize, borderColor: borderColor, forState: state) + } + + + /** + This function sets the icon to UIButton with title (custom font) below it + + - Parameter icon: The icon + - Parameter title: The title + - Parameter font: The font for the title below the icon + - Parameter color: Color for the icon & title + - Parameter backgroundColor: Background color for the button + - Parameter borderSize: Border size for the button + - Parameter borderColor: Border color for the button + - Parameter forState: Control state of the UIButton + + - Version: 1.1 + */ + public func setIcon(icon: FontType, title: String, font: UIFont, color: UIColor = .black, backgroundColor: UIColor = .clear, borderSize: CGFloat = 1, borderColor: UIColor = .clear, forState state: UIControlState) { + + setIcon(icon: icon, iconColor: color, title: title, titleColor: color, font: font, backgroundColor: backgroundColor, borderSize: borderSize, borderColor: borderColor, forState: state) + } } public extension UISegmentedControl { diff --git a/SwiftIcons.podspec b/SwiftIcons.podspec index d4214c5..5d61f86 100644 --- a/SwiftIcons.podspec +++ b/SwiftIcons.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "SwiftIcons" - s.version = "1.0.2" + s.version = "1.1" s.summary = 'SwiftIcons - A library for using different font icons' s.description = 'SwiftIcons library helps you use icons from any of these font icons - Dripicons, Emoji, FontAwesome, Ionicons, Linearicons, Map-icons, Material icons, Open iconic, State face icons, Weather icons' diff --git a/SwiftIcons/Base.lproj/Main.storyboard b/SwiftIcons/Base.lproj/Main.storyboard index c23dd42..70ba32f 100644 --- a/SwiftIcons/Base.lproj/Main.storyboard +++ b/SwiftIcons/Base.lproj/Main.storyboard @@ -48,7 +48,7 @@ -