Apps Developer Blog

Swift

In this short Swift code example, you will learn how to create UITextField in Swift programmatically. The code example below will cover the following: Create UITextField of specific height and width, Position UITextField at the center of the view, Set UITextField backgroundColor, Set UITextField textColor, Set UITextField UITextBorderStyle, Add UITextField as a subview, Set UITextField…

Read More Create UITextField Programmatically

In this short Swift code example, you will learn how to: Find a Documents directory on iOS device in Swift, Write a String value into a file in the Documents directory on an iOS device. let fileName = “myFileName.txt” var filePath = “” // Fine documents directory on device let dirs:[String] = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.allDomainsMask, true)…

Read More Write String Value Into a File in Swift

In this short Swift code example, you will learn how to declare a function that can take variadic parameters. We use a variadic parameter to specify that the parameter can be passed a varying number of input values when the function is called. The below code example will cover: Declare a function with variadic parameters,…

Read More Declare a function with variadic parameters in Swift

In this Swift code example, you will learn how to create UIImageView programmatically and how to load an image from a remote URL. Create UIImageView and UIImage programmatically, Load image data from a remote URL, Learn how to use dispatch_get_global_queue to start a background thread, Learn how to use dispatch_get_main_queue to update UI when the…

Read More UIImageView and UIImage. Load Image From Remote URL.

In this Swift code example, you will learn how to create UITabBarController programmatically. We will first create two View Controllers which will be Tab 1 and Tab 2, and then we will create one more View Controller which will serve as UITabBarController and will hold the two tabs. When a user taps on tab 1,…

Read More Create UITabBarController programmatically

In this Swift code example, you will learn how to create and display UICollectionView in Swift Programmatically. The Swift code example in this tutorial will cover the following: Create UICollectionView programmatically, Set UICollectionView layout UIEdgeInsets, Set UICollectionView item size(width and height), Set UICollectionView background color, Set UICollectionView Item background-color, Implement UICollectionView Delegate method didSelectItemAtIndexPath to…

Read More Create UICollectionView in Swift Programmatically

In this Swift code example, you will learn how to programmatically create UICollectionView and load a list of images from a remote URL. The below swift code example will cover: Create UICollectionView programmatically Set UICollectionView item size(width and height) Set UICollectionView background color Set UICollectionView Item background-color Implement UICollectionView Delegate method didSelectItemAtIndexPath to handle an…

Read More UICollectionView. Load List of Images From Remote Server Url

In this short Swift code example, you will learn how to determine main screen bounds as well as screen height and width in Swift. Get main screen bounds Get screen width Get screen height // Get main screen bounds let screenSize: CGRect = UIScreen.main.bounds let screenWidth = screenSize.width let screenHeight = screenSize.height print(“Screen width =…

Read More Determine Main Screen Height and Width

In this short Swift code example, you will learn how to determine device orientation in Swift. Determine device orientation when the view is about to appear Determine device orientation when device is being rotated to Landscape or Portrait import UIKit class ViewController: UIViewController { var textView:UITextView? override func viewDidLoad() { super.viewDidLoad() } override func viewWillAppear(_…

Read More Determine Device Orientation in Swift

In this short Swift code example, you will learn how to disable rotation of the UIViewController if device is rotated right or left. Note, that if your view is embedded into UINavigationController a different approach is needed. Check Swift Code Examples page to learn how to disable rotation of the view if it is embedded…

Read More Disable Rotation of UIViewController

In this short Swift code example, you will learn how to disable rotation of the UIViewController which is embedded into UINavigationController. We will need to override the shouldAutorotate function and return a value of false, Add to current UIViewController a UINavigationController extension. Disable Rotation of UIViewController Complete Code Example in Swift Below is a very simple…

Read More Disable Rotation of UIViewController Embedded Into UINavigationController

In this Swift code example, you will learn how to play the music mp3 file from a remote URL in Swift. The code example below will cover: Create AVPlayer and AVPlayerItem, Create UIButton programmatically, Create AVPlayerLayer and add it as a subview, Handle the Play button action to Pause and Play music, Set UIImage on…

Read More AVPlayer. Play Music MP3 File From a Remote URL In Swift.

In this Swift code example, you will learn how to add a playback slider to an AVPlayer, so that users can start playing music from any place they wish. The code example below will cover the following: Create AVPlayer and AVPlayerItem, Create UIButton programmatically, Create AVPlayerLayer and add it as a subview, Handle Play Button action…

Read More Add Playback Slider to AVPlayer. Example In Swift.

In this Swift code example, you will learn how to determine user’s current location using CLLocationManager and CLLocationManagerDelegate. The code example below will cover: Request user’s permission for your app to always be able to read user’s location. Optionality you could use requestWhenInUseAuthorization() instead of requestAlwaysAuthorization(), Update projects Info.plist with String values for NSLocationAlwaysUsageDescription and…

Read More Determine User’s Current Location Example in Swift

Free Video Lessons

Enter your email and stay on top of things,

Subscribe!