Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SwiftIcons.podspec #50

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,21 @@ stepper.setIncrementIcon(icon: .ionicons(.iosPlay), forState: .normal)

```

### Using icons in your own attributed strings

```Swift

// Getting icon
let icon: FontType = .fontAwesome(.check)
FontLoader.loadFontIfNeeded(fontType: icon)

// Using it in your NSAttributedString
if let font = UIFont(name: icon.fontName(), size: 15), let iconText = icon.text {
let bulletStr = NSAttributedString(string: iconText, attributes: [NSAttributedStringKey.font: font])
}

```


## Examples

Expand Down
Binary file modified Source/Fonts/Ionicons.ttf
100755 → 100644
Binary file not shown.
4 changes: 3 additions & 1 deletion Source/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<string>2.3.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
13 changes: 7 additions & 6 deletions Source/SwiftIcons.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SwiftIcons.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pod::Spec.new do |s|
s.screenshots = 'https://raw.githubusercontent.com/ranesr/SwiftIcons/master/docs/images/pic01.png'

s.source = { :git => 'https://github.com/ranesr/SwiftIcons.git', :tag => s.version }
s.ios.deployment_target = '10.3'
s.ios.deployment_target = '10.0'
s.source_files = 'Source/SwiftIcons.swift'
s.resource_bundle = { 'SwiftIcons' => 'Source/Fonts/*.ttf' }

Expand Down
8 changes: 4 additions & 4 deletions SwiftIcons.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ranesr.SwiftIcons;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down Expand Up @@ -532,7 +532,7 @@
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = "$(SRCROOT)/Source/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.ranesr.SwiftIcons;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
Expand Down Expand Up @@ -592,7 +592,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -643,7 +643,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 10.3;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
Expand Down
2 changes: 1 addition & 1 deletion SwiftIconsApp/IconDetailViewController.swift

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion SwiftIconsApp/LibraryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LibraryViewController: UICollectionViewController, UICollectionViewDelegat
var bottomBackgroundColors = ["c0392b", "d35400", "f39c12", "27ae60", "16a085", "2980b9", "8e44ad", "B68AA5", "7f8c8d", "2c3e50", "8781bd"]
var objects = ["UIImage", "UIImageView", "UILabel", "UIButton", "UISegmentedControl", "UITabBarItem", "UISlider", "UIBarButtonItem", "UIViewController", "UITextField", "UIStepper"]
var objectNames = ["Image", "Image View", "Label", "Button", "Segmented Control", "Tab Bar Item", "Slider", "Item", "View Controller", "Text", "Stepper"]
var icons: [FontType] = [.ionicons(.images), .fontAwesomeRegular(.building), .fontAwesomeRegular(.grinWink), .ionicons(.iosCircleFilled), .fontAwesomeRegular(.handRock), .ionicons(.iosStar), .ionicons(.iosToggle), .fontAwesomeRegular(.kissBeam), .ionicons(.iphone), .fontAwesomeRegular(.flushed), .fontAwesomeRegular(.smile)]
var icons: [FontType] = [.ionicons(.iosImages), .fontAwesomeRegular(.building), .fontAwesomeRegular(.grinWink), .ionicons(.iosBicycle), .fontAwesomeRegular(.handRock), .ionicons(.iosStar), .ionicons(.iosSwitch), .fontAwesomeRegular(.kissBeam), .ionicons(.iosPhonePortrait), .fontAwesomeRegular(.flushed), .fontAwesomeRegular(.smile)]

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
63 changes: 57 additions & 6 deletions SwiftIconsApp/ObjectsDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
// SOFTWARE.

import UIKit
import SwiftIcons

class ObjectsDetailsViewController: UIViewController {

@IBOutlet var scrollView: UIScrollView!
var index: Int!
var textColors = ["e74c3c", "e67e22", "f1c40f", "2ecc71", "1abc9c", "3498db", "9b59b6", "e4Accf", "95a5a6", "34495e", "6c6998"]
var objects = ["UIImage", "UIImageView", "UILabel", "UIButton", "UISegmentedControl", "UITabBarItem", "UISlider", "UIBarButtonItem", "UIViewController", "UITextField", "UIStepper"]
var textColors = ["e74c3c", "e67e22", "f1c40f", "2ecc71", "1abc9c", "3498db", "9b59b6", "e4Accf", "95a5a6", "34495e", "6c6998", "6c6998"]
var objects = ["UIImage", "UIImageView", "UILabel", "UIButton", "UISegmentedControl", "UITabBarItem", "UISlider", "UIBarButtonItem", "UIViewController", "UITextField", "UIStepper", "NSAttributedString"]

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -118,7 +119,7 @@ class ObjectsDetailsViewController: UIViewController {

case 2:
let label1 = UILabel(frame: CGRect(x: 20, y: 20, width: screenWidth/2-40, height: screenWidth/2-40))
label1.setIcon(icon: .ionicons(.paintbrush), iconSize: 70)
label1.setIcon(icon: .ionicons(.iosBrush), iconSize: 70)
label1.isUserInteractionEnabled = true
label1.tag = 21
let tap21 = UITapGestureRecognizer(target: self, action: #selector(tapped(gesture:)))
Expand All @@ -139,7 +140,7 @@ class ObjectsDetailsViewController: UIViewController {
label3.addGestureRecognizer(tap23)

let label4 = UILabel(frame: CGRect(x: screenWidth/2+20, y: screenWidth/2, width: screenWidth/2-40, height: screenWidth/2-40))
label4.setIcon(prefixText: "Medal ", prefixTextColor: textColor, icon: .ionicons(.ribbonA), iconColor: textColor, postfixText: "", postfixTextColor: textColor, size: nil, iconSize: 40)
label4.setIcon(prefixText: "Medal ", prefixTextColor: textColor, icon: .ionicons(.iosRibbon), iconColor: textColor, postfixText: "", postfixTextColor: textColor, size: nil, iconSize: 40)
label4.isUserInteractionEnabled = true
label4.tag = 24
let tap24 = UITapGestureRecognizer(target: self, action: #selector(tapped(gesture:)))
Expand Down Expand Up @@ -191,7 +192,7 @@ class ObjectsDetailsViewController: UIViewController {
button3.addGestureRecognizer(tap33)

let button4 = UIButton(frame: CGRect(x: screenWidth/2+20, y: screenWidth/2, width: screenWidth/2-40, height: screenWidth/2-40))
button4.setIcon(prefixText: "Happy ", prefixTextFont: font1!, icon: .ionicons(.happy), postfixText: " face", postfixTextFont: font2!, forState: UIControl.State.normal)
button4.setIcon(prefixText: "Happy ", prefixTextFont: font1!, icon: .ionicons(.mdHappy), postfixText: " face", postfixTextFont: font2!, forState: UIControl.State.normal)
button4.isUserInteractionEnabled = true
button4.tag = 34
let tap34 = UITapGestureRecognizer(target: self, action: #selector(tapped(gesture:)))
Expand Down Expand Up @@ -307,7 +308,7 @@ class ObjectsDetailsViewController: UIViewController {

case 7:
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: self, action: #selector(barButtonItem(sender:)))
navigationItem.rightBarButtonItem?.setIcon(icon: .ionicons(.navicon), iconSize: 36, color: textColor, cgRect: CGRect(x: 30, y: 30, width: 30, height: 30), target: self, action: #selector(barButtonItem(sender:)))
navigationItem.rightBarButtonItem?.setIcon(icon: .ionicons(.iosNavigate), iconSize: 36, color: textColor, cgRect: CGRect(x: 30, y: 30, width: 30, height: 30), target: self, action: #selector(barButtonItem(sender:)))

print("")
print("Example Usage")
Expand Down Expand Up @@ -378,6 +379,53 @@ class ObjectsDetailsViewController: UIViewController {

scrollView.addSubview(stepper1)

case 11:

func createParagraphStyle() -> NSParagraphStyle {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.tabStops = [NSTextTab(textAlignment: .left, location: 15, options: [:])]
paragraphStyle.defaultTabInterval = 15
paragraphStyle.firstLineHeadIndent = 0
paragraphStyle.headIndent = 15
return paragraphStyle
}

let label = UILabel(frame: CGRect(x: 20, y: 20, width: screenWidth/2-40, height: screenWidth/2-40))
label.numberOfLines = 0

let mySportsList: [NSAttributedString] = [NSAttributedString(string: "skiing", attributes: [NSAttributedString.Key.font: UIFont(name: "Avenir-Heavy", size: 15.0)!]),
NSAttributedString(string: "hiking", attributes: [NSAttributedString.Key.font: UIFont(name: "Avenir-Heavy", size: 15.0)!]),
NSAttributedString(string: "tennis", attributes: [NSAttributedString.Key.font: UIFont(name: "Avenir-Heavy", size: 15.0)!])]

// preparing a bullet icon in a form of an NSAttributedString
let icon: FontType = .fontAwesomeSolid(.check)
FontLoader.loadFontIfNeeded(fontType: icon)
let bulletStr: NSAttributedString
if let font = UIFont(name: icon.fontName(), size: 15), let iconText = icon.text {
bulletStr = NSAttributedString(string: "\(iconText) ", attributes: [NSAttributedString.Key.font: font, NSAttributedString.Key.foregroundColor: UIColor.green])
} else {
bulletStr = NSAttributedString(string: "•", attributes: [:])
}

let attributedString = NSMutableAttributedString(string: "Sports:\n", attributes: [NSAttributedString.Key.font: UIFont(name: "Avenir-Heavy", size: 18.0)!])
for string in mySportsList {
let bulletString = NSMutableAttributedString(attributedString: bulletStr)
bulletString.append(string)
bulletString.append(NSAttributedString(string: "\n"))
bulletString.addAttributes([NSAttributedString.Key.paragraphStyle: createParagraphStyle()], range: NSMakeRange(0, bulletString.length))
attributedString.append(bulletString)
}

label.attributedText = attributedString
label.isUserInteractionEnabled = true
label.tag = 40
let tap40 = UITapGestureRecognizer(target: self, action: #selector(tapped(gesture:)))
label.addGestureRecognizer(tap40)

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

default:
break
}
Expand Down Expand Up @@ -553,6 +601,9 @@ class ObjectsDetailsViewController: UIViewController {
case 39:
print("button.setIcon(icon: .mapicons(.airport), iconColor: textColor, title: \"AIRPLANE\", font: font!, forState: .normal)")

case 40:
print("let icon: FontType = .fontAwesome(.check)\n FontLoader.loadFontIfNeeded(fontType: icon)\n let myIconAsAttributedString = NSAttributedString(string: icon.text!, attributes: [NSAttributedStringKey.font: UIFont(name: icon.fontName(), size: 15)!]) }")

default:
print("Default")
}
Expand Down
26 changes: 26 additions & 0 deletions scripts/ionicons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
import sys, json
from stringcase import camelcase, titlecase

def main(argv):
if len(sys.argv) != 2:
print('{} <ion-mainfest.json>' % (sys.argv[0]))
sys.exit(2)

mainfestPath = sys.argv[1]
with open(mainfestPath, 'r') as mainfestFile:
mainfest = json.loads(mainfestFile.read())
names = []
cases = []
codePoints = []
for icon in mainfest['icons']:
names.append(r'"%s"' % titlecase(icon['name']).replace('Md ', 'Material ').replace('Ios ', 'iOS '))
cases.append(camelcase(icon['name'].replace('-','_')))
codePoints.append(r'"\u{%s}"' % (icon['code'][2:]))

print(', '.join(names))
print(', '.join(cases))
print(', '.join(codePoints))

if __name__ == "__main__":
main(sys.argv[1:])