Posts

Showing posts with the label swift tutorial

How To Make The Device Vibrate Or Ring- An iOS Swift Tutorial

How To Make The Device Vibrate Or Ring- An iOS Swift Tutorial The iPhones have a built-in ability to alert users by creating some vibration or sound effects. You can trigger the vibration or sound effects by using SystemSound services. This is very useful in many cases while working on iOS Apps. in this tutorial, we'll learn how to trigger the vibration or sound effect on any particular action or button clicks. This is very easy to do and just takes one or 2 lines of code. In this tutorial, I'll just write the code that you need to add in your button's action or any other specific function to make the device vibrate or sound + vibrate both. We'll also see how to make the device vibrate more than once. So let's start.. Before anything, make sure to import  AVFoundation. For Vibrate Only: If you only want to make the device quick vibrate, then this one line of code will do the trick: AudioServicesPlaySystemSound ( kSystemSoundID_Vibrate ) For Sound ...

Web View Using WKWebView iOS Tutorial

Image
WKWebView iOS Tutorial Hi, In today's post, we'll learn how to use WKWebView or simply saying, how to implement web view in iOS applications . I am using Xcode 9 and Swift 4 for this tutorial. So, let's do it using our step by step approach: STEP 1: Open Xcode and create a Single View Application. Give some name to your app, eg. WebViewAppTutorial and make sure to choose Swift as the language, click Next. STEP 2: Here, first we'll embed our app in a navigator controller. For this, just open your Main.storyboard and click on View Controller. Now, select Editor from Xcode Menu bar, and select Embed in > Navigation Controller. STEP 3: Now, open ViewController.swift file and import webkit module. import  WebKit Under your ViewController class , add the webView property as: var webView: WKWebView ! Now, in your class declaration, add one  WKNavigationDelegate  protocol as shown below: class ViewController: UIViewController , WKNav...

How To Parse JSON Data In iOS (Swift 3 + Xcode 8) ?

Image
JSON Data Parsing In iOS Hi, In this post, I'll show you how to fetch and parse JSON data from an URL in your iOS app. First, what is JSON?? JSON stands for "JavaScript Object Notation". JSON is the most popular and light weight format for data-interchange.  In this app, we’ll use http://fixer.io website's API to get the latest currency exchange rates and use them in our iOS app.  So, let’s start and see how to parse JSON data in iOS. First of all, open your Xcode and create a Single View Application.  Give some name to your project and make sure to choose Swift as the language. Click Next. For this post, we don’t need to work in Storyboard. So just open your ViewController.swift file and write following lines of code in your viewDidLoad() method:      override func viewDidLoad() {         super . viewDidLoad ()                  //Give your...

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

Image
How To Add Map Annotations In iOS 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...

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

Image
How To Create UI Slider In iOS?? 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, cl...

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

Image
UI Picker View As Input Type For UI Text Field In iOS 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.  ...