Code Monkey home page Code Monkey logo

textile's Introduction

Build Cocoapod License Version

Textile Logo

Textile

Textile styles your text

Define and use TextStyle

let style = TextStyle { style in
    style.set(.font, UIFont.systemFont(ofSize: 18, weight: .regular))
    style.set(.foregroundColor, .black)
}

let label = UILabel()
label.attributedText = style(text: "Hello World!")

Simple Style

Combining text styles

extension TextStyle {
    static let body = TextStyle { style in
        style.set(.font, UIFont.systemFont(ofSize: 18, weight: .regular))
    }

    static let uppercase = TextStyle { style in
        style.add(transformer: .init(\.localizedUppercase))
    }
}

let combined: TextStyle = .combining(.body, .uppercase)

// or using `+` operator

let combined: TextStyle = .body + .uppercase

The rightmost style has precedence.

Use TextileLabel for convenience

let label = TextileLabel(textStyle: .combining(.body, .uppercase), text: "Hello World!")

Textile Label

Example with a bit more complex styling

let attributedText = NSMutableAttributedString()
attributedText.append("First we need a title\n".style(.heading))
attributedText.append("Here starts the ".style(.body))
attributedText.append("body text".style(.body + .underlined))
attributedText.append(", then suddenly we might want some".style(.body))
attributedText.append(" bold text ".style(.bodyBold))
attributedText.append("in the middle.\n".style(.body))
attributedText.append("...and then some right-aligned text".style(.body + .rightGray))

let label = UILabel()
label.lineBreakMode = .byWordWrapping
label.numberOfLines = 0
label.attributedText = attributedText

Complex

Installation

With cocoapods:

target 'MyApp' do
  pod 'TextileFramework'
end

textile's People

Contributors

aegzorz avatar

Stargazers

Daniel Grönlund avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.