├── .github └── workflows │ └── swift.yml ├── .gitignore ├── Assets ├── simple_string_semantic.png └── simple_string_visual.png ├── AttributedStringStyle.podspec ├── CHANGELOG.md ├── LICENSE ├── Package.swift ├── README.md ├── Sources └── AttributedStringStyle │ ├── AttributedStringBuilder.swift │ ├── AttributedStringStyler.swift │ ├── NSAttributedString+Style.swift │ └── NSAttributedString.Key+Style.swift └── Tests ├── AttributedStringStyleTests ├── AttributedStringBuilderTests.swift ├── AttributedStringStylerTests.swift ├── TestUtils.swift └── XCTestManifests.swift └── LinuxMain.swift /.github/workflows/swift.yml: -------------------------------------------------------------------------------- 1 | name: Swift 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: macOS-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v1 12 | - name: Build 13 | run: swift build -v 14 | - name: Run tests 15 | run: swift test -v 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | 4 | # Xcode 5 | build/ 6 | *.pbxuser 7 | !default.pbxuser 8 | *.mode1v3 9 | !default.mode1v3 10 | *.mode2v3 11 | !default.mode2v3 12 | *.perspectivev3 13 | !default.perspectivev3 14 | xcuserdata/ 15 | *.xccheckout 16 | profile 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | 22 | # Bundler 23 | .bundle 24 | 25 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 26 | # Carthage/Checkouts 27 | 28 | Carthage/Build 29 | 30 | # We recommend against adding the Pods directory to your .gitignore. However 31 | # you should judge for yourself, the pros and cons are mentioned at: 32 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 33 | # 34 | # Note: if you ignore the Pods directory, make sure to uncomment 35 | # `pod install` in .travis.yml 36 | # 37 | Example/Pods/ 38 | /.build 39 | /AttributedStringStyle.xcodeproj 40 | -------------------------------------------------------------------------------- /Assets/simple_string_semantic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/felginep/AttributedStringStyle/97dd0462a70b6a254af5995c1ed5846e0715866a/Assets/simple_string_semantic.png -------------------------------------------------------------------------------- /Assets/simple_string_visual.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/felginep/AttributedStringStyle/97dd0462a70b6a254af5995c1ed5846e0715866a/Assets/simple_string_visual.png -------------------------------------------------------------------------------- /AttributedStringStyle.podspec: -------------------------------------------------------------------------------- 1 | # 2 | # Be sure to run `pod lib lint AttributedStringStyle.podspec' to ensure this is a 3 | # valid spec before submitting. 4 | # 5 | # Any lines starting with a # are optional, but their use is encouraged 6 | # To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html 7 | # 8 | 9 | Pod::Spec.new do |s| 10 | s.name = 'AttributedStringStyle' 11 | s.version = '1.0.1' 12 | s.summary = 'Focus on the semantic and the visual representation of NSAttributedString separately.' 13 | s.homepage = 'https://github.com/felginep/AttributedStringStyle' 14 | s.license = { :type => 'MIT', :file => 'LICENSE' } 15 | s.author = 'Pierre Felgines' 16 | s.social_media_url = 'http://twitter.com/PierreFelgines' 17 | s.source = { :git => 'https://github.com/felginep/AttributedStringStyle.git', :tag => "v#{s.version}" } 18 | s.ios.deployment_target = '9.0' 19 | s.source_files = 'Sources/**/*' 20 | s.framework = 'Foundation' 21 | s.swift_version = '5.0' 22 | end 23 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | All notable changes to this project will be documented in this file. 3 | `AttributedStringStyle` adheres to [Semantic Versioning](http://semver.org/). 4 | 5 | ## [1.0.1] 6 | 7 | ### Updated 8 | 9 | - Update example project settings 10 | - Remove redundant public declaration to fix warning 11 | 12 | ## [1.0.0] 13 | 14 | - First version 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 Pierre Felgines 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "AttributedStringStyle", 8 | products: [ 9 | // Products define the executables and libraries produced by a package, and make them visible to other packages. 10 | .library( 11 | name: "AttributedStringStyle", 12 | targets: ["AttributedStringStyle"]), 13 | ], 14 | dependencies: [ 15 | // Dependencies declare other packages that this package depends on. 16 | // .package(url: /* package url */, from: "1.0.0"), 17 | ], 18 | targets: [ 19 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 20 | // Targets can depend on other targets in this package, and on products in packages which this package depends on. 21 | .target( 22 | name: "AttributedStringStyle", 23 | dependencies: []), 24 | .testTarget( 25 | name: "AttributedStringStyleTests", 26 | dependencies: ["AttributedStringStyle"]), 27 | ] 28 | ) 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AttributedStringStyle 2 | 3 | [![Version](https://img.shields.io/cocoapods/v/AttributedStringStyle.svg?style=flat)](https://cocoapods.org/pods/AttributedStringStyle) 4 | [![License](https://img.shields.io/cocoapods/l/AttributedStringStyle.svg?style=flat)](https://cocoapods.org/pods/AttributedStringStyle) 5 | [![Platform](https://img.shields.io/cocoapods/p/AttributedStringStyle.svg?style=flat)](https://cocoapods.org/pods/AttributedStringStyle) 6 | 7 | ## Blog post 8 | 9 | You can find the associated blog post [here](https://felginep.github.io/2018-11-23/attributed-string-with-style). 10 | 11 | ## Example 12 | 13 | To run the example project, clone the repo, and run `pod install` from the Example directory first. 14 | 15 | ## Requirements 16 | 17 | - iOS 9.0+ 18 | - Swift 4.2 19 | 20 | ## Installation 21 | 22 | AttributedStringStyle is available through [CocoaPods](https://cocoapods.org). To install 23 | it, simply add the following line to your Podfile: 24 | 25 | ```ruby 26 | pod 'AttributedStringStyle' 27 | ``` 28 | 29 | ## How to use it 30 | 31 | Define some abstract style anywhere in your app. For instance. 32 | 33 | ```swift 34 | enum Style { 35 | case regular 36 | case highlighted 37 | } 38 | ``` 39 | 40 | Once your style is defined we have two tools at your disposal: 41 | - `AttributedStringBuilder` that is helpful to create attributed string with styles for range of characters 42 | - `AttributedStringStyler` that defines which visual attributes to apply for each style 43 | 44 | To create your attributed string and focus on the semantic and not the display, use the builder like so: 45 | 46 | ```swift 47 | let content = "A simple string" 48 | let builder = AttributedStringBuilder