Giter VIP home page Giter VIP logo

Cocoapods platforms pod Swift Package Manager compatible

Introduction

The purpose of the BlowMindStyle library is to provide the infrastructure for application styling. BlowMindStyle allows:

  • write reusable styles for views
  • write reusable styles for text formatting (based on SemanticString)
  • add application themes
  • dynamically update views depending on trait collection and theme
  • dynamically update views depending on a model state.

Basic usage

  1. Add resources, that will be used for stylization:
struct ButtonProperties {
    var backgroundColor: UIColor?
    var cornerRadius: CGFloat?
    var titleColor: UIColor?
    var font: UIFont?
    var contentEdgeInsets: UIEdgeInsets?
}
  1. Define style:
final class ButtonStyle<Environment: StyleEnvironmentType>: EnvironmentStyle<ButtonProperties, Environment> { }
  1. Apply resources to view:
extension EnvironmentContext where Element: UIButton {
    var buttonStyle: StylableElement<ButtonStyle<StyleEnvironment>> {
        stylableElement { button, style, resources in
            button.setTitleColor(resources.titleColor, for: .normal)

            let cornerRadius = resources.cornerRadius ?? 0

            if let normalColor = resources.backgroundColor {
                let normalBackground = UIImage.resizableImage(withSolidColor: normalColor, cornerRadius: cornerRadius)

                button.setBackgroundImage(normalBackground, for: .normal)
            } else {
                button.setBackgroundImage(nil, for: .normal)
            }

            button.titleLabel?.font = resources.font ?? UIFont.systemFont(ofSize: UIFont.buttonFontSize)

            button.contentEdgeInsets = resources.contentEdgeInsets ?? .zero
        }
    }
}
  1. Use style:
button.setUpStyles {
    $0.buttonStyle.apply(.primary)
}

For more info see tutorial

Dependencies

Installation

CocoaPods

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
   pod 'BlowMindStyle'
end

Swift Package Manager

In XCode select File/Swift Packages/Add Package Dependency. Type 'BlowMindStyle', select BlowMindStyle project and click 'Next', 'Next'

Tutorial

  1. Preparing the project
  2. Creating your own style
  3. Creating a theme
  4. Switching styles according to the state
  5. Text stylization

blowmindstyle's Projects

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.