Author: Sergey Kargopolov

Software developer

Web: www.appsdeveloperblog.com

The code snippet in this blog post demonstrates how to create a UIButton with a background image. To break it down in details, the following Swift code example will cover how to: Create UIButton and position UIButton within a view, Add UIButton as Subview, Add target action to UIButton to call a local function when the button…

Read More UIButton with Background Image in Swift

This code example demonstrates how to write and read from NSUserDefaults in Swift. The code example below will cover how to: Create a global instance of NSUserDefaults Write and read the following data types from NSUserDefaults: Integer Boolean Double Objects like String, Date and Array of elements Using NSUserDefaults in Swift. Code Example. // Create a…

Read More NSUserDefaults example in Swift

In this Swift code example, you will learn how to disable UIButton. The quickest way to disable the button in Swift is to simply set the button’s isEnabled property to false. For example button.isEnabled = false.  Below is a complete code example in Swift that demonstrates how to: Create new UIButton, Position button within a view,…

Read More Disable UIButton Example in Swift

The two Swift code snippets below are examples of how to compare if two Strings are equal. Check if Two Strings are Equal Using elementsEqual() Let’s assume the two Strings are constants and we need to compare them: let password = “HelloWorld” let repeatPassword = “HelloWorld” if ((password.elementsEqual(repeatPassword)) == true) { print(“Passwords are equal”) } else {…

Read More Compare Two Strings in Swift

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