Found 208 Articles for IOS

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

699 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

136 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

608 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

How to display an image with rounded corners on iOS App using Swift?

Samual Sam
Updated on 30-Jun-2020 05:55:51

3K+ Views

To make an image with round corners or to make any view or button or any UI element with round corners in swift, we need to access the corner radius property of its layer. Every UI element in iOS is based on a layer.First of all, let’s add an UIImageView Object in our storyboard. Or let’s create one programmatically.Below is a function that will programmatically create an image view and add an image to it.func addImage(imageName img: String) {    let imageView = UIImageView()    imageView.frame = CGRect(x: 10, y: 20, width: 200, height: 200)    imageView.contentMode = . scaleAspectFill ... Read More

How to handle right-to-left and left-to-right swipe gestures on iOS App?

karthikeya Boyini
Updated on 30-Jun-2020 05:56:36

1K+ Views

To handle gestures in iOS application we’ll create an application with swift and see with help of an example. This can be done in two ways, with storyboard or programmatically.Method 1 − With storyboardFirst we’ll drag a swipe gesture recognizer from our object library and drop it in our View controller in which we want to add the swipe gesture.Then click on the gesture, press control and drag in your view controller class to create its connection.Make sure the sender of that action is UISwipeGestureRecognizer and the action looks something like this:@IBAction func swipeMade(_ sender: UISwipeGestureRecognizer) { }Now the swipe ... Read More

Advertisements