Found 208 Articles for IOS

How can I get battery level and state (plugged in, discharging, charging, etc) in iOS?

Sadiqaadil
Updated on 11-Sep-2019 08:25:16

533 Views

In this post we will be seeing how to get the battery state in iOS.So let’s get started.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “BatteryState”Step 2 − Open Main.storyboard and add two label as shown below. On this label we will show battery status.Step 3 − Enable the battery state monitoring, using the following code. You can put this code in viewDidLoad of ViewControllerUIDevice.current.isBatteryMonitoringEnabled = trueStep 4 − Declare a variable to hold the battery state. We will name this variable batteryState. From this variable we are returning UIDevice.current.batteryState, that would ... Read More

How to get the distance between two geographic locations in iOS using Swift?

Sadiqaadil
Updated on 11-Sep-2019 08:18:31

1K+ Views

In this post we will learn how to calculate the distance between two geo locations.We will show the distance between two points on a label.To do so follow the steps belowStep 1 − Open Xcode → New Project → Single View Application → Let’s name it “FindDistance”Step 2 − Open Main.storyboard and add two labels as shown below.Step 3 − Attach one @IBOutlet for the bottom label. Name it distanceLabelStep 4 − Import CoreLocation framework in ViewControllerStep 5 − Add two points between which we want to find the distance as variablesvar firsLocation = CLLocation(latitude:34.54545, longitude:56.64646) var secondLocation = CLLocation(latitude: ... Read More

How to programmatically prevent scrolling in WebView of iOS?

Sadiqaadil
Updated on 11-Sep-2019 08:13:30

1K+ Views

Disabling scrolling in WebView in iOS is very simple.The ‘scrollView’ property of the WebView is exposed by iOS.You will just need to disable the scrolling of the corresponding scrollView using below code.webView.scrollView.isScrollEnabled = falseThe above code will disable the scrolling on WebView.If you were just looking to disable scrolling in web view above code would do that. If you want to know from scratch how to load WebView and disable scrolling. Follow along.Let’s create a sample project in XCode and learn the WebView loadingStep 1 − Open Xcode → New Project → Single View Application → Let’s name it “WebViewScrollDisabling”Step ... Read More

How to customise iOS button to set text and color?

Sadiqaadil
Updated on 03-Jul-2020 12:32:40

2K+ Views

In this post we will be seeing how to customise iOS button.So let’s get started.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “CustomiseButton”Step 2− Open Main.storyboard and add a button as shown below. We will customize this buttonThere are two ways to customise this buttonUsing StoryboardStep 1 − Click on the buttonStep 2 − In the right panel, in the attribute inspector you can change the text color, text and background color of the button as shown belowRun the project you will see the customise button as belowNow we will see the ... Read More

How to check if a text field is empty or not in swift?

Sadiqaadil
Updated on 11-Sep-2019 07:57:25

3K+ Views

It’s very easy to check whether text field is empty or not in Swift.You will first need to check whether text is available or not in text field i.e. it’s not nil, then you will need to check if its present then its empty or not. Assuming myTextField is your text field variable name, you can do the followingif let text = myTextField.text, text.isEmpty {    // myTextField is not empty here } else {    // myTextField is Empty }Above code will check if textField is empty or not.If you want to look at how the text field can ... Read More

How to add a border to the top and bottom of an iOS View?

Sadiqaadil
Updated on 11-Sep-2019 07:52:04

4K+ Views

In this post we will learn how to add top and bottom border to view.In this example we will take as sample view and add borders to it.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “AddBorderTopAndBottom”Step 2 − Open Main.storyboard add a UIView to it as shown below.Step 3 − Add one @IBOutlet for the view, name it centerView.Step 4 − We will write separate method to add borders to this view. To add borders to this view we will create two layers with desired thickness. We will set the frame of ... Read More

How do you animate the change of background color of a view on iOS?

Sadiqaadil
Updated on 11-Sep-2019 07:47:17

1K+ Views

In this post we will learn how to change the background color of view with animation.In this example we will change background color of view on click of a button. On clicking the button the background color will change to red, then on next click it would change to blue, on next click to red again.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “ChangeBGColor”Step 2 − Open Main.storyboard add a button as shown belowStep 3 − Add one @IBAction for touchUpInside of ‘Change Background’ button. Name the function as changeBackgroundClicked.Step 4 − ... Read More

How to generate Unique ID of device for iPhone/iPad using Swift?

Mohtashim M
Updated on 30-Aug-2019 11:44:07

1K+ Views

UDID(Unique Device Identifier) − A sequence of 40 hexadecimal characters that uniquely identify an iOS device.Since from iOS 5, Apple has deprecated the UIDevice unique identifier, that means the traditional way of getting the unique id. Apple removed the truly unique identifier and introduced an identifier for each vendor i.e UUID that's the same for all apps for a given developer for each user, but varies between developers and between devices.Apple has defined an instance property identifier for the vendor, which is an alphanumeric string that uniquely identifies a device to the app’s vendor.You can read more about it here: ... Read More

How to add 1 day to a Date in iOS/iPhone?

Mohtashim M
Updated on 30-Aug-2019 11:40:21

116 Views

A Date value encapsulates a single point in time, independent of any particular calendrical system or time zone. Date values represent a time interval relative to an absolute reference date.Here we will be seeing how to add 1 day to date,For this, we will be using Playground, Copy the below code in Playground,let date = Date() let addedDate = Calendar.current.date(byAdding: .day, value: 1, to: date) print(addedDate ?? "")

How to create Picker programmatically from array in iOS?

Mohtashim M
Updated on 30-Aug-2019 11:38:47

2K+ Views

A picker view displays one or more wheels that the user manipulates to select items. Each wheel—known as a component—has a series of indexed rows representing the selectable items.UIPicker is one of the important components and almost used in most of the applications. You’ll see them mostly in form-based applications.You can read more about it here: https://developer.apple.com/documentation/uikit/uipickerviewIn this post, we will be seeing how to create UIPicker programmatically from and array and load array values into it.So let’s get started, Step 1 − Open Xcode and create a single view application and name it PickerSample.Step 2 − Open ViewController.swift, Since ... Read More

Previous 1 ... 3 4 5 6 7 ... 21 Next
Advertisements