Posts

Showing posts from August, 2017

How To Add Map Annotations In iOS (Swift 3 + Xcode 8) ?

Image
Hi, In this tutorial, I’ll show you how to place an annotation on map in your iOS apps. Its super easy and you can learn to add annotations in map just by reading this small post only once. So, let’s get started and see how to do it.
First of all, open your Xcode and create a Single View Application. Now, give some name to your project and make sure to choose Swift as the language.
Now, drag and drop a Map View from objects library to your storyboard’s view controller. Now, place some constraints on this map view. For that, just click on Add constraint’s icon on right bottom corner of your screen and add 0 from all sides so that map can be visible on whole app screen. You can check below image for your reference:


After adding constraints, ctrl+drag this map view to your ViewController.swift file and create its outlet.
Now, open your ViewController.swift file. Here, first import MapKit framework.
import MapKit
Now, paste following code in your viewDidLoad() method:
overridefunc viewDidLoad() …

How To Create UI Slider In iOS (Swift 3 + Xcode 8) ?

Image
Hi, In this tutorial, I’ll show you how to use sliders in your iOS apps. Its super easy to learn and implement. So, without wasting any time, let’s start and see how to do it. :)
First of all, open your Xcode and create a new Single View Application. 


Give some name to your product and make sure to choose Swift as the language. Click Next.


Now, open Main.storyboard and drag 2 objects on your view controller. First drag a Slider (which is of course if you want to use sliders :| ) and then drag a label to display the values of this slider.
Now, add some constraints on both of these objects. For example, you can add following constraints on your label:


Similar way, add some constraints on the slider as well. You can add following constraints on your slider:


Also, don't forget to assign default, minimum and maximum values to your slider from attribute inspector as shown in the picture below:



Now, click on assistant editor from top right corner of your Xcode and create outlet for your label…

UI Picker View As Input Type For UI Text Field In iOS (Swift 3 + Xcode 8)

Image
Hi, In this post, I’ll show you how to create an UI Picker View for UI Text Field in iOS. I am using Swift 3 and Xcode 8 for this tutorial.

So, let’s start and see how to do it..

First of all, open your Xcode and create a Single View Application.


Now, open your main.storyboard and drag a textfield on your view controller. Add some constraints on this text field as shown in the picture below:


Now, create an outlet for your added text field. For that make sure to open up the assistant editor and ctrl+drag the UI textfield to your ViewController.swift file. 
Once its done, close the assistant editor and open your ViewController.swift file. Here, first add UIPickerViewDataSource and UIPickerViewDelegate methods in your class declaration as shown below:
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate
Now, first create your picker view object. 
var picker = UIPickerView()
Also, create an array with some elements. We’ll use this array elements as an input choi…

How To Show Alert With Action In Xcode Using Swift ?

Image
Hi, In this tutorial, I’ll show you how to create alerts for your iOS apps. Alerts are very common in iOS apps and requires almost in every app here and there. Alerts are also very easy to implement in Swift. You can learn it just by going through this post only once.
So, let’s start and see how to create alerts for your iOS applications..
FYI, You can also watch this tutorial on my YouTube channel here: How To Show Alert With Actions in iOS

First of all, open your Xcode and select Single View Application, click Next.


Now, give some name to your project and make sure to choose Swift as the language. Once you're in the project editor, open your ViewController.swift file. 


Here, first we’ll create a function for setting up our alert and then we’ll call this function in our viewDidLoad() method.


So, to create this function, just write these lines of code:


func myAlert(title: String, message: String){

let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)

       …