To run the example project, clone the repo, and run pod install
from the Example directory first.
BEPureLayout is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'BEPureLayout'
BEPureLayout adds some custom UI classes, short-hand helper-functions to well-known PureLayout library that helps developers quickly create common UIComponents like pure UIView, UIButton, UILabel, UIImageView,... Besides, this library add some common-used methods for adding constraints.
BEViewController is a subclass of UIViewController which was implemented methods for easy NavigationBar configurations and setUps
- Layout code should be implemented inside
override func setUp()
- DataBinding should be implemented inside
override func bind()
- For NavigationBar customization, override property
var preferredNavigationBarStype: BEViewController.NavigationBarStyle
- For changing navigationBar's backgroundColor, use
setNavigationBarBackgroundColor(:)
- For changing navigationBar's textStyle, use
setNavigationBarTitleStyle(textColor: UIColor, font: UIFont)
init(width:, height:, backgroundColor:, cornerRadius:)
init(width:, height:, backgroundColor:, cornerRadius:, label:, labelFont:, textColor:, contentInsets:)
init(text:, textSize:, weight:, textColor:, numberOfLines:, textAlignment:)
init(width:, height:, backgroundColor:, cornerRadius:, imageNamed:, contentMode:)
init(width:, height:, backgroundColor:, cornerRadius:, font:, keyboardType:, placeholder:, autocorrectionType:, autocapitalizationType:, spellCheckingType:, textContentType:, isSecureTextEntry:, horizontalPadding:, leftView:, leftViewMode:, rightView:, rightViewMode:)
Note: You don't have to provide all properties to initializers. Only provide known or required properties, then other properties will be set by default. For example, if the view's width is based on superview's width, then just remove the width property from the initializer: UIView(height: 30)
and add needed width constraint to superview
- autoPinToTopLeftCornerOfSuperview
- autoPinToTopRightCornerOfSuperview
- autoPinToBottomLeftCornerOfSuperview
- autoPinToBottomRightCornerOfSuperview
- autoPinToTopLeftCornerOfSuperviewSafeArea
- autoPinToTopRightCornerOfSuperviewSafeArea
- autoPinToBottomLeftCornerOfSuperviewSafeArea
- autoPinToBottomRightCornerOfSuperviewSafeArea
- autoPinBottomToSuperViewSafeAreaAvoidKeyboard
This subclass of UIScrollView contains a contentView
that is hugged inside ScrollView itself and only scrollable in a defined direction provided by property scrollableAxis
.
Everything that needs to add to ScrollView should be added only to its contentView
.
For example:
let scrollView = ContentHuggingScrollView(scrollableAxis: .vertical)
view.addSubview(scrollView)
scrollView.autoPinEdgesToSuperviewEdges()
let label = UILabel(text: "Very long text.....")
scrollView.contentView.addSubview(label)
label.autoPinEdgesToSuperviewEdges()
This subclass of UIView allows you to create flexible tableHeaderView
for UITableView. After any layout changes in this BETableHeaderView, it will reassign itself as tableView's tableHeaderView and triggle re-layout in tableView.
The usage of BETableHeaderView is quite simple, you can subclass it and override function commonInit to layout its content:
class MyTableHeaderView: BETableHeaderView {
lazy var label = UILabel(text: "TableViewHeaderView is loading...", textSize: 20, weight: .bold, textColor: .black, numberOfLines: 0)
override func commonInit() {
super.commonInit()
addSubview(label)
label.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 16, left: 16, bottom: 0, right: 16))
}
}
Then you can construct MyTableHeaderView
alongside with UITableView
using initializer:
let tableHeaderView = MyTableHeaderView(tableView: tableView)
And freely change content of headerView without any concern about re-layouting
tableHeaderView.label.text =
"""
TableHeaderView was loaded
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
"""
For more detail, see Example project
bigearsenal, [email protected]
BEPureLayout is available under the MIT license. See the LICENSE file for more info.