Safe area fix guide for earlier versions of iOS

Safe area layout is introduced in iOS11 but what can we do if we are supporting < iOS 11 and we have a xib view that is initiated in a ViewController and somehow the upper part of the xib view appears behind the NavigationBar??? To fix this, simply add this line in your viewDidLoad.

self.edgesForExtendedLayout = UIRectEdge.init(rawValue: 0)

For more information visit EdgesForExtendedLayout at Apple.

Embed a UIViewController in a UINavigationController Programmatically

We know how to embed a ViewController in a NavigationController in Storyboard. However, I came across a scenario where I had to initiate it programmatically. The code:

let viewController = MyViewController()
let nav = UINavigationController(rootViewController: viewController)
self.navigationController?.present(nav, animated: true, completion: nil)

Swift set height get height!

When making a somewhat complicated iOS app you may need to change the width or height of a UIView. At times we also need to set a new value for the x position or the y position.

I created some methods to add functionality to class UIView.  I have wanted this extension for so long, but Apple have failed to deliver.

Usage:

61BA5D9D-EE15-49E9-92CF-CB068E8061C0.png

Easy? Yeh! See the extension below.

FED08F65-CC5E-4C76-BAD0-679E78A09663

Enjoy!