Git Product home page Git Product logo

gaikan's Introduction

Gaikan

[![Build Status](https://travis-ci.org/akane/Gaikan.svg?branch=travis)](https://travis-ci.org/akane/Gaikan) [![CocoaPods Compatible](https://img.shields.io/cocoapods/v/Gaikan.svg)](https://img.shields.io/cocoapods/v/Gaikan.svg)

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, ...).

Properties

Depending on your view type (UILabel, UIScrollView, UITextField, ...) some properties may or may not have any effect. Here are all the available style properties you can use:

Property name Apply to Description Available since
Background UIView Sets a background to your view (color, gradient and or image) 0.3
Border UIView Sets the layer Border 0.1
Clip UIView Make the content of the view hidden if larger than the frame 0.4
Color UILabel Sets the text color 0.1
CornerRadius UIView Sets the view layer corner radius 0.4
Font UILabel Sets the text font 0.1
Opacity UIView Change the view alpha (0...1) 0.4
TextAlign UILabel Text horizontal alignment 0.2
TintColor UIView Sets the tint color 0.1
Transform UIview Apply transforms (rotation, ...) 0.4
Visible UIView Sets the view hidden property 0.1

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

Installing

Gaikan can be installed either using CocoaPods or Carthage.

CocoaPods

Run the following command from your project folder:

pod install Gaikan

Advanced usage

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 [
    .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 with the ultimate goal of releasing it as Open Source Software. We will continue working and investing on it.

We encourage the community to contribute to the project by opening tickets and/or pull requests.

License

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

gaikan's People

Contributors

siemensikkema avatar viteinfinite avatar pjechris avatar readmecritic avatar brandons avatar

Stargazers

MohsinAli avatar

Watchers

MohsinAli avatar  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.