×

iOS Swift Framework


What this framework is about ?

Many programmers love to create an iOS App programmatically. It provides an efficient and flexible way to create an app. Many programmers prefer Storyboard but still, for dynamic and complex User Interfaces, Storyboard is seriously a nightmare.

I created this simple Swift framework because every time I create any new project, the files in this framework is mandatory for me to quickly create and save my time. This framework includes Autolayouts Category which can save developers from writing complex constraints every time.

Download the Project here. ❯

For example

Suppose you want to create a simple Label using Autolayout. Then you have to write complex and lengthy constraints everytime.

 let label = UILabel()
        superView.addSubview(label)
        label.textColor = UIColor .white
        label.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight(rawValue: 1.0))
        label.text = "Label added to superview as subview"
        
        label.translatesAutoresizingMaskIntoConstraints = false
        let topLabelConstraint = NSLayoutConstraint(item: label, attribute: .top, relatedBy: .equal, toItem: superView, attribute: .top, multiplier: 1, constant: 12)
        superView.addConstraint(topLabelConstraint)
        
        let leftLabelConstraint = NSLayoutConstraint(item: label, attribute: .left, relatedBy: .equal, toItem: superView, attribute: .left, multiplier: 1, constant: 20)
        superView.addConstraint(leftLabelConstraint)
        
        let rightLabelConstraint = NSLayoutConstraint(item: label, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 300)
        superView.addConstraint(rightLabelConstraint)
        
        let heightLabelConstraint = NSLayoutConstraint(item: label, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: 24)
        superView.addConstraint(heightLabelConstraint)
        

After using Framework

Using Autolayouts Category, you can create anything with simplified methods. centerXAlign method will center the label in X-Axis. Similarly, many methods are available and sample example to understand how to use Extensions in Swift are available.

 let label = UILabel()
        self.view.addSubview(label)
        label.autolayout()
        label.centerXAlign()
        label.centerYAlign()
        label.height(24)
        label.text = "Label Created using Autolayouts"
        label.textColor = UIColor.tealColor()
        label.font = UIFont.cocoFont(12.0)

UIColors+App.Swift

Gives you access of all the necessary colors required for any decent app.

UIFont+App.Swift

This file contains mostly used fonts in mordern Apps nowdays and much more.

Sample App

Basic App which will illustrate how to use files in given project.


Download the Project here. ❯