Swiftpack.co - bigearsenal/BEPureLayout as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Useful initializers for UIViews using PureLayout
.package(url: "https://github.com/bigearsenal/BEPureLayout.git", from: "0.4.0")


CI Status Version License Platform


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 + BENavigationController

BEViewController is a subclass of UIViewController which was implemented methods for easy NavigationBar configurations and setUps

  • BEViewController should be embeded in a BENavigationController
  • 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

New methods for adding constraint

  • 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)

let label = UILabel(text: "Very long text.....")



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() {
        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, bigearsenal@gmail.com


BEPureLayout is available under the MIT license. See the LICENSE file for more info.


Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.


Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics