Skip to content

Framework that will help to orginize styles in your app

License

Notifications You must be signed in to change notification settings

sparklone/BlowMindStyle

 
 

Repository files navigation

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

# Podfile
use_frameworks!

target 'YOUR_TARGET_NAME' do
   pod 'BlowMindStyle'
end

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

About

Framework that will help to orginize styles in your app

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 99.1%
  • Ruby 0.9%