GithubHelp home page GithubHelp logo

chainkit's Introduction

ChainKit

Swift 链式编程库,持续更新中……

感谢: ChainKit | KMUIMaker | ApplyStyleKit | BlockKit

License Platform

Installation

Requirements

  • iOS 10.0 or later
  • Swift 5.0
  • Xcode 11.0

Carthage

TODO:

CocoaPods

TODO:

使用

let button = UIButton(type: .system)

// 配置 UI 样式
button.chain
    .frame(x: 100, y: 500, width: 200, height: 45)
    .addTarget(self, action: #selector(aaa))
    .title(text: "Button", for: .normal)
    .title(front: .systemFont(ofSize: 24))
    .add(to: self.view)

// 添加按钮事件
button.chain
    .frame(x: 100, y: 500, width: 200, height: 45)
    .addTarget(self, action: #selector(buttonAction(sender:)))
    .title(text: "Button", for: .normal)
    .title(front: .systemFont(ofSize: 24))
    .addAction(for: [.touchDown, .touchDragEnter], action: {
        $0  .makeLightShdow()
            .title(front: .systemFont(ofSize: 22))
    })
    .addAction(for: [.touchUpOutside, .touchUpInside, .touchCancel, .touchDragExit], action: {
        $0  .makeDefaultShdow()
            .title(front: .systemFont(ofSize: 24))
    })

// UIView 可以添加 tap 事件
UIView().chain
    .frame(x: 100, y: 200, width: 200, height: 40)
    .corner(radius: 20)
    .tap(action: {
        print("456")
    })
    .tap(action: { [weak self] in
        guard let this = self else { return }
        this.navigationController?.pushViewController(ViewController(), animated: true)
    })
    .tap(action: {
        print("789")
    })
    .add(to: self.view)

进阶

自定义函数

extension Chain where Base: UILabel {
    
    @discardableResult
    public func makeDefaultLabel() -> Self {
        self.backgroundColor(.yellow)
            .textAlignment(.center)
            .text(color: .green)
            .font(.boldSystemFont(ofSize: 30))
            .numberOfLines(0)
            .origin(x: 100, y: 300)
        return self
    }
}

开源协议

MIT 协议

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.