Found 201 Articles for IOS

How to change the font and color on the UITextView in iOS?

Mohtashim M
Updated on 30-Aug-2019 10:50:31
Changing font and color on UITextView is simple, you just need to update the .textColor and .font property on UITextView object, Here we will be seeing how to do so.So let’s get started, Open Main.storyboard and add UITextView as shown below, Create @IBOutlet of UITextView and name it, textView.    @IBOutlet var textView: UITextView!In your viewDidLoad method of ViewController.swift write below lines, textView.textColor = UIColor.cyan textView.font = UIFont(name: "Callout", size: 20)Final Code should look like, import UIKit class ViewController: UIViewController {    @IBOutlet var textView: UITextView!    override func viewDidLoad() {       super.viewDidLoad()       textView.textColor = ... Read More

How to change background color of TableView items on iOS?

Mohtashim M
Updated on 30-Aug-2019 10:43:34
Changing the background color of table view items is different from changing the background color of the table view. New programmers may often confuse between these two things, In this post, we will be seeing how to change the background color of TableView items i.e. cells.So let’s get started.For changing the background color of the table view cell, you should change the contentView.backgroundColor property of the cell.Add the below code in your cellForRowAt indexPath method, cell.contentView.backgroundColor = UIColor.cyanYour method should look like something below, func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {    let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: ... Read More

How to create and use Global Variable in swift

Mohtashim M
Updated on 30-Aug-2019 10:41:04
As per the Apple document – “Global variables are variables that are defined outside of any function, method, closure, or type contextBefore we learn how to create global variables, first let us understand completely what are they.Consider “W” which is inside the inner circle, can access everything which will be inside the inner circle. On the other hand, A can access everything which is inside the outer circle as well as everything inside the inner circle, so the scope of “A” is global as he can access both the circles.So a global variable can access everything inside the bigger and ... Read More

How do you create a date object from a date in Swift xcode?

Mohtashim M
Updated on 30-Aug-2019 10:36:38
Coming from Objective C- Background now we don’t need to use NSDate as Swift has defined its own struct type Date. Date bridges to the NSDate class. You can use these interchangeably in code that interacts with Objective-C APIs.To read more about Date you can check official apple docs https://developer.apple.com/documentation/foundation/dateIn this post we will be seeing how one can create date object, So let’s get started we will be using Playground for this purpose.First, we will be seeing how to get the current date and time (UTC), to get current date and time, create an object of Date, enter the ... Read More

Disable Orientation Change in iOS

Mohtashim M
Updated on 07-Aug-2019 14:13:36
There are numerous application which either runs on Portrait mode or in Landscape mode.Restricting the application in one of the mode is important to achieve this.In this post we will see how to restrict the orientation or disable the orientation to one mode.If you want the application to be running only in Portrait mode, Below your viewDidLoad method copy the below line of codeoverride var supportedInterfaceOrientations: UIInterfaceOrientationMask {    get {       return .portrait    } }This will lock the landscape mode for your application. Similarly by replacing .portrait to .landscape will run your application in landscape mode.If ... Read More

How to get current date and time from internet in iOS?

Mohtashim M
Updated on 07-Aug-2019 14:11:06
Working with date and time can be tricky, I’ve seen new programmers struggling with date and time. In almost all the application you will be required to get the date and multiple operations are dependent on it.Here we will be seeing how to get the current date and time in swift.In this post we will be seeing how to get the current time and UTC time.For getting the UTC time, paste below code in playground.let utcDate = Date() print(utcDate)If you wish to get the time stamp of your location, paste the below code in playground.let dateObj = Date() let datetformatter ... Read More

How to get the differences between two dates in iOS?

Mohtashim M
Updated on 07-Aug-2019 14:09:03
Getting difference between two dates is easy. You should know how to play between the dates.We will be using DateFormatter class for formatting the dates.Instances of DateFormatter create string representations of  NSDate objects, and convert textual representations of dates and times into  NSDate objects.You can read more about it here https://developer.apple.com/documentation/foundation/dateformatterWe will also be using Calendar structure, apple has provided beautiful documentation of it,  https://developer.apple.com/documentation/foundation/calendarSo let’s get started.Open Xcode, New Playground.Copy the below codeimport UIKit // create object of DateFormatter and Calendar let formatter = DateFormatter() let calendar = Calendar.current // specify the format, formatter.dateFormat = "dd-MM-yyyy" // specify the start ... Read More

How to use both front and back cameras simultaneously in iOS?

Mohtashim M
Updated on 07-Aug-2019 14:06:56
As of now, there’s no way you can access both front and back cameras simultaneously. As both cameras have different session, as soon as one will start other session will die.As per the apple developer forum answered by Apple support team −“Apps cannot capture from the front and back cameras simultaneously. You can switch from one to the other (with a short delay between) but not both at the same time”

How to check if an iOS program is in foreground or in background?

Mohtashim M
Updated on 07-Aug-2019 14:06:28
Knowing when the application is in foreground or in background is important as being an iOS developer we need to handle multiple events such as background downloads, events if the app comes to foreground.Here we will see how to check if the application is in background or foreground.We will be using Notification Center for that, To read more about it you can refer apple document. https://developer.apple.com/documentation/foundation/notificationcenterA notification dispatch mechanism that enables the broadcast of information to registered observers. We will be adding observer to the same and will be getting the call.Step 1 −  Open Xcode → New Project → Single ... Read More

How do I create a TableView with rounded corners in iOS?

Mohtashim M
Updated on 07-Aug-2019 14:05:02
Table View is one of the most important and fundamental part of iOS application, Every iOS developer should be familiar with it.Almost every application you see in App store use table view.Table views on iOS display a single column of vertically scrolling content, divided into rows. Each row in the table contains one piece of your app’s content. For example, the Contacts app displays the name of each contact in a separate row, and the main page of the Settings app displays the available groups of settingsYou can read more about table view here,  https://developer.apple.com/documentation/uikit/uitableviewIn this post we will see ... Read More
Previous 1 ... 4 5 6 7 8 ... 21 Next
Advertisements