Mohtashim M

Mohtashim M

28 Articles Published

Articles by Mohtashim M

Page 2 of 3

How can I change the text color of the Navigation Bar on iOS?

Mohtashim M
Mohtashim M
Updated on 30-Aug-2019 740 Views

Changing the text color of the navigation bar is tricky and easy at the same time, In this post, we will be seeing how one can change the text color of navigation bar in swift.So let’s get started, Embed your view controller in Navigation controller as shown below and name navigation item for that particular controller as a tutorial as shown, Now navigate to AppDelegate.swift and add below lines in didFinisheLaunchingWithOptions method.func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {    // Override point for customization after application launch.    let textColor = [NSAttributedString.Key.foregroundColor:UIColor.green]    UINavigationBar.appearance().titleTextAttributes = textColor ...

Read More

How to get the dimensions of a view in iOS App?

Mohtashim M
Mohtashim M
Updated on 30-Aug-2019 1K+ Views

Getting dimensions of a view is easy, In this post, we will see how one can get the dimensions of a view in iOS.Let’s get started, Step 1 − Open Xcode and create a single view application and name it SampleView.Step 2 − Open Main.storyboard and add UIView as shown below, Step 3 − Create @IBOutlet of the view in ViewController.swift.@IBOutlet var sampleView: UIView!Step 4 − In viewDidLoad of ViewController.swift write the following code, print(sampleView.frame.size)Run the application to see the size.Complete codeimport UIKit class ViewController: UIViewController {    @IBOutlet var sampleView: UIView!    override func viewDidLoad() {       ...

Read More

How to create a WebView in an iOS App using Swift?

Mohtashim M
Mohtashim M
Updated on 30-Aug-2019 7K+ Views

As an iOS developer, you will come across multiple scenarios where you have to display something in web, for that we use WebView.As per Apple, − It is an object that displays interactive web content, such as for an in-app browser.So in this post, we will be seeing how to create WebView and load the data in it.So let’s startStep 1 − Open Xcode and create a single view application and name it WebViewSample.Step 2 − Open ViewController.swift file and import the WebKit module. import WebKitStep 3 − Add a property of WebKit in ViewController.swift.var webView: WKWebView!Step 4 − Add ...

Read More

How to obtain the phone number of the iOS phone programmatically?

Mohtashim M
Mohtashim M
Updated on 30-Aug-2019 2K+ Views

Getting a phone number of the iOS device is programmatically is not feasible. Apple doesn’t encourage it. You can get the phone number using private API’s but that will result in rejection of your application from the Apple App Store.As per the apple development guideline apps should be self-contained in their bundles, and may not read or write data outside the designated container area and device number is not available within your application’s container.As per Apple developer forum −Regardless of which programming language you use, Apple doesn't make the phone number associated with a device available to developers.

Read More

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

Mohtashim M
Mohtashim M
Updated on 30-Aug-2019 2K+ Views

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
Mohtashim M
Updated on 30-Aug-2019 2K+ Views

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
Mohtashim M
Updated on 30-Aug-2019 3K+ Views

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

Disable Orientation Change in iOS

Mohtashim M
Mohtashim M
Updated on 07-Aug-2019 1K+ Views

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
Mohtashim M
Updated on 07-Aug-2019 555 Views

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
Mohtashim M
Updated on 07-Aug-2019 570 Views

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
Showing 11–20 of 28 articles
Advertisements