Declarative view styling in Swift. Inspired by CSS modules.

Overview

Gaikan

CocoaPods Compatible Carthage compatible Build Status

Gaikan gives you powerful styling capabilities using a declarative DSL in Swift. Inspired by React: CSS in JS and CSS modules.

To style UIView(s) just give them a StyleRule object:

let myLabelStyle = StyleRule() { (inout style: StyleRule) -> () in
  style.color = UIColor.redColor()
  style.border = Border(width: 1, color: UIColor.greenColor())
  style.font = UIFont(name: "Courier", size: 24)
}

self.label.styleInline = myLabelStyle

Check out the sample to see how to well integrate Gaikan into a project.

Features

  • Apply a simple style using styleInline....
  • ... or make theming using styleClass (see below for more information).
  • You can share styles using extends method to avoid repeating yourself.
  • You can style depending on your control state (enabled, highlighted, ...).
  • You can style NSAttributedString!

Properties

Check out our page on properties to find which one to use to style your views.

Starting with 0.4, we also added VirtualView. This allow you to apply style effects on some non UIView attributes/objects:

NSObject Virtual view Description Available since
UINavigationBar titleStyle Sets title navigation bar style 0.4

Advanced usage

NSAttributedString

Just call NSAttributedString(string:"Hello", style: yourStyle) to get a styled NSAttributedString.

Alternatively you can use style.textAttributes to transform StyleRule into any NSAttributedString compatible dictionary.

Theme

Theme packages together multiple Style definitions to make a whole set.

public class SampleTheme : Theme {
  /// Non static is important if you want to reference them from InterfaceBuilder
  lazy let logo = Style(...)
  lazy let title = Style(...)
}

class CustomView: UIView {
  typealias ThemeType = RailTheme

  @IBOutlet weak var title: UILabel!
  @IBOutlet weak var footnote: UILabel!
  @IBOutlet weak var logo: UIImageView!
  @IBOutlet weak var button: UIButton!

  override func awakeFromNib() {
    self.title.styleClass = SampleTheme().logo
    self.logo.styleClass = SampleTheme().title
  }
}

You can also apply themes right from InterfaceBuilder:

Extends

You can extend your styles to reuse common features:

func primary() -> Style {
  return [
    .Color: UIColor.greenColor()
  ]
}

func large() -> Style {
  return [
    .Font: UIFont.systemFontOfSize(18)
  ]
}

func merged() -> Style {
  return Style().extends(primary(), large())
  // color: green, font: 18
}

States

You can define styles for states. They'll extend from the default state :

func style() -> Style {
  return Style() { (inout style: StyleRule) -> Void in
    style.tintColor = UIColor.whiteColor()
  }
  .state(.Selected, attributes: [
      .TintColor: UIColor.grayColor().colorWithAlphaComponent(0.6)
  ]
}

Don't hesitate to take a look at the sample to better understand how it works.

Contributing

This project was first developed by Xebia IT Architects in Paris, France. We will continue working and investing on it.

We encourage the community to contribute to the project by opening tickets and/or pull requests. Here a some of the subjects we are interested in:

  • Add UIStackView attributes (distribution, spacing, ...).
  • Support for multiple layout engines (AutoLayout, LayoutKit, Flexbox, ...)
  • Allow to define 1+ borders and corner radius. Currently defining border and radius set the 4 of them (top, bottom, left, right).
  • Better support for IBDesignable (if possible).
  • Add debugging information (style name, inheritance, ...).
  • Better integration with NSAttributedString.
  • Support for traits.
  • Anything you have in mind!

License

Gaikan is released under the MIT License. Please see the LICENSE file for details.

Comments
  • Use Carthage for dependencies

    Use Carthage for dependencies

    I don't want to start a flamewar with Cocoapods supporters but this way I was able to support both Carthage and Cocoapods for including Gaikan in a project. Quick and Nimble are installed using Cartfile.private meaning they won't be compiled for users of the framework but they remain available for testing.

    see #6

    opened by siemensikkema 9
  • Add UINavigationBar support

    Add UINavigationBar support

    This PR adds support for the following keys of the titleTextAttributes property:

    • NSForegroundColorAttributeName
    • NSFontAttributeName
    • NSShadowAttributeName
    opened by viteinfinite 3
  • Fixing issues on rounded corners + borders

    Fixing issues on rounded corners + borders

    Allow borders to be correctly drawn on views having rounded corners. Also, fixing a major visual issue on antialiasing which prevented borders from having smooth corners.

    opened by viteinfinite 1
  • Versioning issue

    Versioning issue

    I am trying to access the version 0.8.0 of Gaikan as i need Swift 3.0 support, however current pod always target 0.7.0. Did you forget to tag 0.8 on Master?

    opened by ghost 1
  • Add a custom CALayer to UIView

    Add a custom CALayer to UIView

    It might be nice to use a custom CALayer object instead of modifying UIView.layer. This would allow us to do implement "tricky" effects setting only one border or corner radius (top, left, bottom, right).

    This would also be a first step to handle view bound changing.

    opened by pjechris 1
  • Unable to install using Carthage

    Unable to install using Carthage

    These are some of the things preventing this:

    • There is no Cartfile with the KVOController dependency
    • The Pods directory is included which causes Carthage to try to build the Pods.xcodeproj

    Would you be okay with using Carthage for Gaikan's own dependencies instead of Cocoapods? I think it will be easier to support both Carthage and Cocoapods for using the framework. I can try to create a pull request for this if you'd like.

    opened by siemensikkema 0
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    Created with cocoapods-readme.

    opened by ReadmeCritic 0
Owner
null
👕👚 Theme management in Swift

Themes Story Ever want to support Night mode? Or skin the app differently depending on the seasons? Or toggle features according to paid status? Well,

Khoa 238 Dec 26, 2022
The official Swift style guide for raywenderlich.com.

The Official raywenderlich.com Swift Style Guide. Updated for Swift 5 This style guide is different from others you may see, because the focus is cent

raywenderlich 12.5k Dec 30, 2022
Style guide & coding conventions for Swift projects

This repository is no longer active. A guide to our Swift style and conventions. This is an attempt to encourage patterns that accomplish the followin

GitHub 4.8k Jan 4, 2023
A style guide for Swift.

Table Of Contents Overview Linter Standards Naming Conventions File Structure Types Statement Termination Variable Declaration Self Structs & Classes

Prolific Interactive 171 Oct 4, 2022
LinkedIn's Official Swift Style Guide

Swift Style Guide Make sure to read Apple's API Design Guidelines. Specifics from these guidelines + additional remarks are mentioned below. This guid

LinkedIn 1.4k Dec 13, 2022
A starter project for Sample Project in swift 5, Xcode 12.5

A starter project for Sample Project in swift 5, Xcode 12.5 (also bridging header included so you could use objective c code in it as well ).

Zeeshan Haider 51 Oct 27, 2022
Theme handling macOS Appkit (Swift/Objective-C)

DSFAppearanceManager A class for simplifying macOS appearance values and detecting setting changes (Swift/Objective-C). Why? If you're performing cust

Darren Ford 8 Nov 1, 2022
A lightweight CSS parser for parsing and creating CSS stylesheets

SwiftCSSParser A lightweight CSS parser for Swift that uses cssparser (cpp) under the hood. Basic usage Here's a simple code snippet to get you starte

null 9 Jul 20, 2022
Write clean, concise and declarative network code relying on URLSession, with the power of RxSwift. Inspired by Retrofit.

ReactiveAPI Reactive API library allows you to write clean, concise and declarative network code, with the power of RxSwift and URLSession! iOS Demo A

Sky UK Ltd 79 Nov 19, 2022
Swift Modules, a swift module (or package) manager

Swift Modules The Swift Modules manager similar to the JavaScript world's npm and bower

Jan Kuča 60 Jun 3, 2021
An opinionated starting point for awesome, reusable Swift 5 modules

Swift 5 Module Template Use this template as a starting point for any Swift 5 module that you want other people to include in their projects. STATUS:

William Entriken 419 Dec 5, 2022
Interface-oriented router for discovering modules, and injecting dependencies with protocol in Objective-C and Swift.

ZIKRouter An interface-oriented router for managing modules and injecting dependencies with protocol. The view router can perform all navigation types

Zuik 631 Dec 26, 2022
A toolbox of AI modules written in Swift: Graphs/Trees, Support Vector Machines, Neural Networks, PCA, K-Means, Genetic Algorithms

AIToolbox A toolbox of AI modules written in Swift: Graphs/Trees, Linear Regression, Support Vector Machines, Neural Networks, PCA, KMeans, Genetic Al

Kevin Coble 776 Dec 18, 2022
An opinionated starting point for awesome, reusable Swift 5 modules

Swift 5 Module Template Use this template as a starting point for any Swift 5 module that you want other people to include in their projects. STATUS:

William Entriken 419 Dec 5, 2022
Swift modules for game development.

Introduction I have been making iOS games with Swift, SceneKit, and SpriteKit since 2015 when I was in high school. After working on over a hundred pr

Kelin Lyu 3 May 29, 2022
decoupling between modules in your iOS Project. iOS模块化过程中模块间解耦方案

DecouplingKit 中文readme Podfile platform :ios, '7.0' pod 'DecouplingKit', '~> 0.0.2' DecouplingKit, decoupling between modules in your iOS Project. D

coderyi 139 Aug 23, 2022
Custom MacBook login screen and pam modules using multipeer connectivity and usb hardware checks with iOS app for sign in.

Custom MacBook login screen and pam modules using multipeer connectivity and usb hardware checks with iOS app for sign in.

null 2 Aug 17, 2022
Used MVVM with with clear seperation to each modules

Classifieds Deployment Target: iOS 14.0, Xcode Version: Xcode 12.0 + Notes Used MVVVM with with clear seperation to each modules. Noted that image url

Muhammed Azharudheen 1 Nov 16, 2021
Modules to use with The Composable Architecture

TCA-Modules Modules to use with The Composable Architecture You can run Examples

Stanislau Parechyn 1 May 20, 2022
React-native-photo-editor - Photo editor using native modules for iOS and Android

?? Image editor using native modules for iOS and Android. Inherit from 2 available libraries, ZLImageEditor (iOS) and PhotoEditor (Android)

Baron Ha. 244 Jan 5, 2023