Found 98 Articles for IPhone/iPad

How to make an HTTP request on iOS App using Swift?

Fendadis John
Updated on 30-Jul-2019 22:30:25

668 Views

To make an http request in iOS we’ll make use of DataTask and sessions. We’ll create configuration, sessions, url, request, and dataTask objects. Let’s see the steps that we’ll go through.The HTTP request can be of different types, it depends on what kind of request we want to make to our server. Below are the basic types of requests.“GET”, ”POST”, ”PUT”, ”DELETE” , we can make use of any of these according to our API. The basics remain same for each kind of request, which are shown below. Let’s see these examples with DELETE type of request.First of all we ... Read More

Dynamically change TableView Cell height in Swift

George John
Updated on 30-Jul-2019 22:30:25

6K+ Views

To change the height of tableView cell in ios dynamically, i.e resizing the cell according to the content available, we’ll need to make use of automatic dimension property. We’ll see this with the help of an sample project.Create an empty project and go to it’s viewController class, conform it to UITableViewDataSource and UITableViewDelegate.Now, In the below code, we will first create a table, then register a cell for that table, and add some table properties.We’ll set the table view delegate and table view datasource.Finally we’ll add the table view to view. Then we’ll call this function inside the viewDidLoad method ... Read More

Adding Navigation Bar programmatically iOS using Swift

Samual Sam
Updated on 30-Jul-2019 22:30:25

3K+ Views

To add navigation bar programmatically we’ll go through a series of steps that are mentioned below. We’ll be doing this in ViewWillLayoutSubviews method of our viewController.Getting the width of the current View.let width = self.view.frame.widthCreating a navigation bar with the width of our current view and height of 44 px which is the default height of a navigation bar.let navigationBar: UINavigationBar = UINavigationBar(frame: CGRect(x: 0, y: 0, width: width, height: 44))Adding the newly created navigation bar to our view.self.view.addSubview(navigationBar)We can further extend this example to add a title and a button to our View. The complete result should look something ... Read More

How to restrict UITextField to take only numbers in Swift?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

5K+ Views

In iOS apps sometimes we need to restrict our text field to take only numbers as an input, this can be done in several ways, let’s see some of them.Method 1: Changing the Text Field Type from storyboard.Select the text field that you want to restrict to numeric input.Go to its attribute inspector.Select the keyboard type and choose number pad from there.Method 2: Programmatically limiting inputs to number.Select the text fieldCreate its outlet in the view controller.Conform the view controller to UITextFieldDelegateSet the text field’s delegateAdd the following functionfunc textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool ... Read More

How to hide the status bar in a iOS App using Swift?

Samual Sam
Updated on 30-Jul-2019 22:30:25

2K+ Views

Sometimes in our application, we need to hide the status bar, navigation bar, and other things and only show the content we want to display. In this article, we’ll see how to hide the status bar in our application. To hide status bar in our iOS application using swift language we need to go through very basic steps.We can hide the status bar in two general ways. Both of these methods involve a common step.Common StepGo to Your info.plist file.Add a key called “View controller-based status bar appearance” and set its value to NO.This was a common step we’ll use ... Read More

How to get the MAC address of an iOS/iPhone programmatically?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

680 Views

In iOS versions previous to 7.0 getting the MAC address of device was possible. But with new iOS version it has been disabled for the apps to access MAC address of the device.When it is accessed or requested on current version of iOS it always returns 02:00:00:00:00:00. This has been implemented by apple because of privacy concerns. If your app needs to uniquely identify a device, apple recommends to use UDID/ UUID instead of MAC. In swift we can useUIDevice.current.identifierForVendor Which as per apple documentation says that, The value of this property is the same for apps that come from ... Read More

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

Samual Sam
Updated on 30-Jul-2019 22:30:25

131 Views

To create a date object in swift we’ll use DateComponents() of swift. We can do this In two ways. We’ll use Playground to test our code instead of simulator.We’ll use date component and calendar to create a date. We can create date component in two ways.Method 1Creating date using the default initializer of DateComponent().var date = DateComponents.init( calendar: , timeZone: , era: , year: , month: , day: , hour: , minute: , second: , nanosecond: , weekday: , weekdayOrdinal: , quarter: , weekOfMonth: , weekOfYear: , yearForWeekOfYear: )This will ask all the things like calendar type, date, day, month, ... Read More

How to remove border in navigationBar in swift?

karthikeya Boyini
Updated on 30-Jun-2020 06:01:47

2K+ Views

To remove the border from a navigation bar in swift, we just need to add a few lines of code. Let’s see how the navigation bar looks when we run it without changing anything.Now let’s try to hide the line/ border shown in the above result.The navigation bar has two things that give it the default view of a grey shadow along with bottom line as shown above. One is the background image, and the other is the shadow image.First, we’ll hide the shadow image, by setting it to empty image and see how it looks.In your viewDidLoad add the ... Read More

How to detect swipe vertically on a ScrollView using Swift?

Samual Sam
Updated on 30-Jul-2019 22:30:24

600 Views

To detect swipe in scrollView we will need to make use of some tricks as scroll view does not natively give the directions of scroll made on it. We’ll see this with help of an example.Create an empty project, add scroll view to the view as per your requirement.Give them constraint as required in the application.From the object library, drag and drop a swipe gesture recognizer right above the Scroll View.Select the gesture recognizer, go to its attribute inspector and from there, select the swipe option and set the value as “up”.When you do this, now your gesture recognizer can ... Read More

How to add a Submit button after the end of the tableview using Swift?

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

1K+ Views

To add a submit button at the end of a table view, we can make use of table view footers. Let’s see this with help of an example where we’ll add a footer view to our table, and inside the table, we will add code for adding button at the bottom of the table view.Create a new project first, then inside the view controller add the following code which will initialize the table, add a section and a few rows to the table.func initTableView() {    let tableView = UITableView()    tableView.frame = self.view.frame    tableView.dataSource = self    tableView.delegate ... Read More

Advertisements