Skip to content

Commit

Permalink
Readying for 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
ranesr committed Apr 5, 2017
1 parent 0f7f430 commit dd3cf8a
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 6 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

```


Expand Down
104 changes: 104 additions & 0 deletions Source/SwiftIcons.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion SwiftIcons.podspec
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion SwiftIcons/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<action selector="goToGithub:" destination="992-F2-xEZ" eventType="touchUpInside" id="I3n-uX-RS9"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Version: 1.0.2" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p4a-eR-qB1">
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Version: 1.1" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="p4a-eR-qB1">
<rect key="frame" x="30" y="377" width="315" height="30"/>
<constraints>
<constraint firstAttribute="height" constant="30" id="szw-oy-t1T"/>
Expand Down
16 changes: 14 additions & 2 deletions SwiftIcons/ObjectsDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,27 @@ class ObjectsDetailsViewController: UIViewController {

let button6 = UIButton(frame: CGRect(x: screenWidth/2+20, y: screenWidth-20, width: screenWidth/2-40, height: screenWidth/2-40))
button6.setIcon(prefixText: "Pulse ", prefixTextFont: font1!, prefixTextColor: .darkGray, icon: .openIconic(.pulse), iconColor: textColor, postfixText: " icon", postfixTextFont: font2!, postfixTextColor: .purple, forState: .normal, iconSize: 40)


let button7 = UIButton(frame: CGRect(x: 20, y: 3*screenWidth/2-40, width: screenWidth/2-40, height: screenWidth/2-80))
button7.setIcon(icon: .emoji(.ferrisWheel), title: "Ferris Wheel", color: textColor, forState: .normal)

let button8 = UIButton(frame: CGRect(x: screenWidth/2+50, y: 3*screenWidth/2-40, width: screenWidth/2-100, height: screenWidth/2-80))
button8.setIcon(icon: .weather(.rainMix), iconColor: textColor, title: "RAIN MIX", titleColor: .red, font: font!, backgroundColor: .clear, borderSize: 1, borderColor: textColor, forState: .normal)

let button9 = UIButton(frame: CGRect(x: 20, y: 2*screenWidth-60, width: screenWidth/2-40, height: screenWidth/2-40))
button9.setIcon(icon: .mapicons(.airport), iconColor: textColor, title: "AIRPLANE", font: font!, forState: .normal)

scrollView.addSubview(button1)
scrollView.addSubview(button2)
scrollView.addSubview(button3)
scrollView.addSubview(button4)
scrollView.addSubview(button5)
scrollView.addSubview(button6)
scrollView.addSubview(button7)
scrollView.addSubview(button8)
scrollView.addSubview(button9)

scrollView.contentSize = CGSize(width: screenWidth, height: 3*screenWidth/2-40)
scrollView.contentSize = CGSize(width: screenWidth, height: 5*screenWidth/2-80)
break

case 4:
Expand Down
Binary file modified docs/images/pic01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dd3cf8a

Please sign in to comment.