Author: Sergey Kargopolov

Software developer

Web: www.appsdeveloperblog.com

In this blog post, you will learn how to create a UIBarButtonItem with Image in Swift. It is going to be a very short and simple Swift code example, that demonstrates how to: Create UIBarButtonItem programmatically, Create UIImage programmatically, Add image to UIBarButtonItem, Add target action to UIBarButtonItem to call a local function. import UIKit class…

Read More UIBarButtonItem with Image Example in Swift

In Swift, you can load HTML files into your WKWebView from a file that is part of your App Bundle. Before you use the below code snippet, please make sure that the HTML file you want to display in WKWebView is added to your project. Load Local HTML File to a WKWebView let myUrl = myProjectBundle.url(forResource: “my-html-file”,…

Read More WKWebView. Load HTML File from App Bundle.

In this short Swift code example, you will learn how to create and customize UITextView programmatically in Swift. The code example below will cover the following: Create UITextView programmatically, Position UITextView at a specific location within a view, Position UITextView at the center of the view, Change UITextView text color, Change UITextView background color, Set…

Read More Create and Customize UITextView Programmatically in Swift

In this short Swift code example, you will learn how to create UITextView programmatically in Swift. Create UITextView programmatically Position UITextView at a specific location within a view Position UITextView at the center of the view Change UITextView text color Change UITextView background color let textView = UITextView(frame: CGRect(x: 20.0, y: 90.0, width: 250.0, height:…

Read More Create UITextView Programmatically in Swift

In this short Swift code example, you will learn how to create and customize UITextView programmatically in Swift. Create UITextView programmatically Position UITextView at the center of the view Change UITextView background colour Create UITapGestureRecognizer Add UITapGestureRecognizer to main view Add UITextView as a subview Create a function to handle Tap away event import UIKit…

Read More Dismiss UITextView Keyboard When User Taps Away

In this short Swift code example, you will learn how to check if file exists at specified path. Find a Documents directory on device Check if file exists at specified file path let fileNameToDelete = “myFileName.txt” var filePath = “” // Fine documents directory on device let dirs : [String] = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.allDomainsMask, true) if…

Read More Check if a File Exist

In this short Swift code example, you will learn how to perform a time consuming task in background thread in Swift, to keep mobile app responsive to user actions while the task is being executed and how to update UI from an async task once background task has completed. Do some task in background thread…

Read More Time Consuming Task in Background Thread in Swift

In this Swift code example, you will learn how to: Create UIBarButtonItem programmatically, How to set right side bar button item(rightBarButtonItem), How to set left side bar button item(leftBarButtonItem), How to set target action on UIBarButtonItem to call a custom function when the button is tapped. Below is a very simple code example in Swift…

Read More Create UIBarButtonItem Programmatically

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.