Swiftpack.co -  UsiantsevStepanSaritasa/DownSwift as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
UsiantsevStepanSaritasa/DownSwift
Simple and lightweight Swift library that helps to define text style areas in given string with your own configuration, apply those styles and convert string into attributed string.
.package(url: "https://github.com/UsiantsevStepanSaritasa/DownSwift.git", from: "0.0.7")

DownSwift

Build Status MIT licensed codebeat badge

Simple and lightweight Swift library that helps to define text style areas in given string with your own configuration, apply those styles and convert string into attributed string.

Installation

Using CocoaPods:

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
    pod 'DownSwift'
end

Replace YOUR_TARGET_NAME and then, in the Podfile directory, type:

$ pod install

Be careful with pod's version! Sometimes CocoaPods can miss the latest version within default installation so there are solutions:

  1. Run pod update in terminal within Podfile directory after pod's installation;

OR

  1. Strictly define pod's version in Podfile:
# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
# Where '0.0.x' is a pod's version
    pod 'DownSwift', '~> 0.0.x'
end

Using Swift Package Manager:

To add DownSwift to your project, select File → Swift Packages → Add Package Dependency and enter the GitHub URL for DownSwift.

Check Adding Package Dependencies to Your App for detailed instructions.

How to use

First of all, import library and initialize main class:

import DownSwift

class YourBeautifulClass {
    ...
    let downSwift = DownSwift()
    ...
}

Then create text style areas in needed string using special symbols:

* - for bold style

~ - for italic style

| - for strikethrough style

\\ - for skipping special symbols that are mentioned above

DownSwiftConfig default values:

public struct DownSwiftConfig {
    public var regularFont: UIFont = .systemFont(ofSize: 17)
    public var regularFontColor: UIColor = .black
    public var boldFont: UIFont = .boldSystemFont(ofSize: 17)
    public var boldColor: UIColor = .black
    public var italicFont: UIFont = .italicSystemFont(ofSize: 17)
    public var italicColor: UIColor = .black
    public var strikethroughFont: UIFont = .systemFont(ofSize: 17)
    public var strikethroughFontColor: UIColor = .black
    public var strikethroughLineColor: UIColor = .black
    
    ...
}

Example (without custom text styles):

  let string = "Hello and *welcome* to the ~example area!~ We are |sad| ~happy\\*~ that you are *here*!!!"
  let attributedString = downSwift.parse(string)
  
  yourLabel.attributedText = attributedString

Output:

Hello and welcome to the example area! We are sad happy* that you are here!!!

Example (with custom text styles)

DownSwift allows you to customize font and font color for each of the styles. Also you can customize strikethrough line color!

You just need to create your own DownSwiftConfig entity.

You can customize any of given styles but you can also skip some properties if needed, in that case skipped properties will take values by default.

For example:

  let string = "Hello and *welcome* to the ~example area!~ We are |sad| ~happy\\*~ that you are *here*!!!"
  
  // For custom fonts you can use any UIFont. For colors use UIColor.
  // For this example I've used "Oswald-Regular" and "Oswald-Bold" fonts.
  var customConfig = DownSwiftConfig()
  
  customConfig.regularFont = customRegularFont
  customConfig.boldFont = customBoldFont
  customConfig.boldColor = .systemBlue
  customConfig.italicColor = .systemRed
  customConfig.strikethroughLineColor = .gray
  
  yourTextLabel.attributedText = downSwift.parse(string, config: customConfig)

Output:

img

License

DownSwift is available under the MIT license. Check LICENSE file for more info.

GitHub

link
Stars: 3
Last commit: 5 days ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

0.0.7 - Strikethrough style fix
5 days ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API