Skip to content

Commit

Permalink
Merge pull request #26 from shtnkgm/feature/swift5
Browse files Browse the repository at this point in the history
Supporting Swift 5.0
  • Loading branch information
kazuhiro4949 authored Apr 28, 2019
2 parents db9c55f + 06c548e commit 55a9540
Show file tree
Hide file tree
Showing 33 changed files with 177 additions and 1,118 deletions.
109 changes: 109 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
### https://raw.github.com/github/gitignore/7f765e3f2a66a318d8be813cf5fc0cd93cc67ed0/Swift.gitignore

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## Build generated
build/
DerivedData/

## Various settings
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/

## Other
*.moved-aside
*.xccheckout
*.xcscmblueprint

## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/
#
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
#
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/


### https://raw.github.com/github/gitignore/7f765e3f2a66a318d8be813cf5fc0cd93cc67ed0/Global/Xcode.gitignore

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3


425 changes: 0 additions & 425 deletions Carthage/Build/iOS/52CA5B32-A8A5-360C-BC03-BDB20585EE2F.bcsymbolmap

This file was deleted.

422 changes: 0 additions & 422 deletions Carthage/Build/iOS/5BFC2728-8BFD-3A34-9AEA-6B11464DBABA.bcsymbolmap

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

Binary file removed Carthage/Build/iOS/StringStylizer.framework/Info.plist
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.
48 changes: 23 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
![Cocoapods compatible](https://cocoapod-badges.herokuapp.com/v/StringStylizer/1.1.1/badge.png)
![Swift 4.2](https://img.shields.io/badge/Swift-4.2-orange.svg)
![Swift 5.0](https://img.shields.io/badge/Swift-5.0-orange.svg)

Type strict builder class for [NSAttributedString](https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/).

Expand All @@ -13,17 +13,17 @@ Building NSAttributedString is so difficult because it requires us to remember a

NSAttributedString has the following format.
```swift
let attr: [String: AnyObject] = [
NSForegroundColorAttributeName: UIColor.whiteColor(),
NSFontAttributeName: UIFont(name: "HelveticaNeue", size: 14)
let attr: [NSAttributedString.Key: Any] = [
.foregroundColor: UIColor.white,
.font: UIFont(name: "HelveticaNeue", size: 14)
]
let str = NSAttributedString(string: "some text", attributes: attr)
```

StringStylizer enable developers to read and write their code in a linear manner.
If you wanna convert String to NSAttributedString which has some colors, sizes and fonts, you can write that as follows.
```swift
let str = "some text".stylize().color(.whiteColor()).size(14).font(.HelveticaNeue).attr
let str = "some text".stylize().color(.white).size(14).font(.HelveticaNeue).attr
```

## Feature
Expand All @@ -33,7 +33,7 @@ let str = "some text".stylize().color(.whiteColor()).size(14).font(.HelveticaNeu

## Requirements
- iOS 8.0+
- Swift 4.0~ or Swift 3.2~
- Swift 5.0~ or Swift 4.0~ or Swift 3.2~

## Installation
### Carthage
Expand Down Expand Up @@ -69,7 +69,7 @@ $(SRCROOT)/Carthage/Build/iOS/StringStylizer.framework
```
+ Write Import statement on your source file
```
Import StringStylizer
import StringStylizer
```

### CocoaPods
Expand Down Expand Up @@ -108,23 +108,21 @@ open .xcworkspace

## Example

```swift
let label = UILabel(frame: CGRectMake(0, 0, 100, 50))

// build NSAttributedString.
let greed = "Hi, ".stylize().color(0x2200ee).size(12).font(.HelveticaNeue).attr

// build NSAttributedString with ranges.
let msg = "something happened ".stylize()
.range(0..<9) .color(0x009911).size(12).font(.HelveticaNeue)
.range(10..<UInt.max).color(0xaa22cc).size(14).font(.HelveticaNeue_Bold).attr

// build NSAttributedString objects and join them.
let name = "to ".stylize().color(0x23abfc).size(12).font(.HelveticaNeue).attr +
"you".stylize().color(0x123456).size(14).font(.HelveticaNeue_Italic).underline(.StyleDouble).attr

label.attributedText = greed + msg + name
```
```swift
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 50))

// build NSAttributedString.
let greed = "Hi, ".stylize().color(0x2200ee).size(12).font(.HelveticaNeue).attr

// build NSAttributedString with ranges.
let msg = "something happened ".stylize()
.range(0..<9) .color(0x009911).size(12).font(.HelveticaNeue)
.range(10..<UInt.max).color(0xaa22cc).size(14).font(.HelveticaNeue_Bold).attr

// build NSAttributedString objects and join them.
let name = "to ".stylize().color(0x23abfc).size(12).font(.HelveticaNeue).attr +
"you".stylize().color(0x123456).size(14).font(.HelveticaNeue_Italic).underline(.double).attr
```

This sample generates a styled label.

Expand All @@ -138,7 +136,7 @@ extension StringStylizer {
.color(0x123456)
.size(14)
.font(.HelveticaNeue_Italic)
.underline(.StyleDouble)
.underline(.double)
.attr
}
}
Expand Down
Loading

0 comments on commit 55a9540

Please sign in to comment.