In this tutorial we will explain the lifecycle of UIViewController in iOS, these methods will run in the following order:
1- init?(coder aDecoder: NSCoder)
If you are using storyboards this is where the controller is initialized, it is called one time only during the view controller lifetime.
Creates the view that the controller manage, the view controller calls this method when its view property is requested but is currently nil.
This method loads or creates a view and assign it to the view property. Continue reading “UIViewController lifecycle explained”
You can change UITextField placeholder color programmatically or using interface builder
Changing UITextField placeholder color in Swift 3
1- Create a new UITextField subclass and override its
layoutSubviews() and insert in it this line of code
self.setValue(UIColor.init(red: 178/255.0, green: 34/255.0, blue: 78/255.0, alpha: 0.5), forKeyPath: "_placeholderLabel.textColor")
Continue reading “How to change UITextField placeholder color in Swift 3 and Interface Builder”
UITextField Underlined In Swift 3
Create a custom UITexField and add this method to it then override
layoutSubviews() and call it from there
let border = CALayer()
let lineWidth = CGFloat(0.3)
border.borderColor = UIColor.lightGray.cgColor
border.frame = CGRect(x: 0, y: self.frame.size.height - lineWidth, width: self.frame.size.width, height: self.frame.size.height)
border.borderWidth = lineWidth
self.layer.masksToBounds = true
Good to know How to change UITextField placeholder color
How to detect if app is running for the first time
You can detect if the application is launched for the first time using NSUserDefaults.
Just by looking for a key called “launchedBefore” for example and if its not found then the application is running for the first time.
if not found then create it.
Add the following code to didFinishLaunchingWithOptions() in AppDelegate.swift file Continue reading “How to detect if application run for the first time in iOS using Swift 3”
Create the custom UITableViewCell from a xib file
In this tutorial we will create a custom cell from xib file and learn how to use it in UITableView using Swift 3
Create Xcode project
1- Create a new Xcode project and select “Single View Application” template and click next
2- Type you project name, in my case i named it “CellExample” and select Swift from Language list and iPhone from Devices list and click next
3- select a location for your project then click finish.
Create UITableViewCell class and xib
4-Now create a new file and select “Cocoa Touch Class” and press next Continue reading “Custom UITableViewCell from xib file in Swift 3”