FlashUI 1.0.1

FlashUI 1.0.1

TifaTsubasa 维护。



FlashUI 1.0.1

  • TifaTsubasa

FlashUI

Version License Platform

为什么使用它?

使用链式调用加速 UI 代码编写

目前您输入

let stackView = UIStackView()
self.stackView = stackView
stackView.axis = .vertical
stackView.frame = CGRect(x: 100, y: 200, width: 100, height: 300)
view.addSubview(stackView)
    
let btn = UIButton()
self.aBtn = btn
btn.setTitle("AAA", for: .normal)
btn.setTitleColor(.red, for: .normal)
    
stackView.addArrangedSubview(btn)

使用 FlashUI 后变为

stackView = UIStackView().axis(.vertical)
  .frame(x: 100, y: 200, width: 100, height: 300).superview(view)

aBtn = stackView.add {
  UIButton().normalTitle("AAA").normalTitleColor(.red)
}

要求

iOS 9+

安装

FlashUI 通过 CocoaPods 提供。安装它,只需将以下行添加到您的 Podfile 中

pod 'FlashUI'

用法

1. 显示评论

UIView().backgroundColor(.black)
  .cornerRadius(10).clipsToBounds()
  .shadow(color: .red, radius: 3, offset: CGSize(width: 2, height: 2), opacity: 0.5)
  .border(color: .blue, width: 1)
  .superview(view)

2. UIButton

UIButton().adjustsImageWhenHighlighted(false)
  .normalTitle("A").normalTitleColor(.white)
  .disabledTitle("A").disabledTitleColor(.lightGray)
  .touchUpInside(target: self, action: #selector(onClick))
//      .touchDown(target: self, action: #selector(onClick))
  .superview(view)

3. UITableView

tableView = UITableView(frame: view.bounds, style: .plain).dataSource(self).delegate(self)
  .rowHeight(72).sectionHeaderHeight(40)
  .tableFooterView(UIView())
  .registerCell(TestTableViewCell.self)
  .registerHeaderFooterView(TestTableHeaderView.self)
  .registerHeaderFooterView(TableFooterView.self)
  .contentInset(top: 0, left: 0, bottom: 49, right: 0)
  .separatorStyle(.none).superview(view)
let cell = tableView.dequeueReusableCell(TestTableViewCell.self)
let header = tableView.dequeueReusableHeaderFooterView(TestTableHeaderView.self)

4. UICollectionView

collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout)
  .registerCell(TestCollectionViewCell.self)
  .registerHeaderView(CollectionHeaderView.self)
  .registerFooterView(CollectionFooterView.self)
  .contentInset(top: 44, left: 0, bottom: 0, right: 0)
  .delegate(self).dataSource(self)
  .backgroundColor(.white).superview(view)
let cell = collectionView.dequeueReusableCell(TestCollectionViewCell.self, for: indexPath)
let header = collectionView.dequeueReusableHeaderView(CollectionHeaderView.self, for: indexPath)
let footer = collectionView.dequeueReusableFooterView(CollectionFooterView.self, for: indexPath)

5. UIStackView

let stackView = UIStackView().axis(.vertical).superview(view)

let titleLabel = UILabel().text("Title").textAlignment(.center)
stackView.add { titleLabel }

let submitBtn = stackView.add {
  UIButton().normalTitle("Submit").normalTitleColor(.black)
    .frame(x: 0, y: 0, width: 200, height: 40)
}

6. UIGestureRecognizer

view.tapGestureRecognizer(target: self, action: #selector(onClick))
view.panGestureRecognizer(target: self, action: #selector(onPan))

作者

Yuri, [email protected]

许可证

FlashUI 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。