Found 98 Articles for IPhone/iPad

How to detect if an iOS application is in background or foreground?

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

3K+ Views

To detect if an iOS application is in background or foreground we can simply use the UIApplication just like we can use it to detect many other things like battery state, status etc.Let’s see how we can do this in our application. We’ll make use of shared resources of our Application which are stored in UIApplication.shared. We can use it like shown below −print(UIApplication.shared.applicationState)The shared.application state is an enum of type State, which consists of the following as per apple documentation.public enum State : Int {    case active    case inactive    case background }The case active means that ... Read More

How to extract the last 4 characters from NSString?

karthikeya Boyini
Updated on 30-Jun-2020 05:49:10

727 Views

To extract last 4 characters from a string in swift we can use the internal functions of String class in swift.With new release every time methods have been modified, deprecated, added and improved in swift. Swift provides different methods to achieve the same. Let’s see these ways of doing it with a few examples.Method 1 − SubstringsIn swift three we were allowed to use a method called substring in which we could pass the string, it’s last index and the offset from which we wanted to trim the string.Let’s see an example of the same:var Str1 = "12312$$33@" print(Str1.substring(from:Str1.index(Str1.endIndex, offsetBy: ... Read More

How to use MBProgressHUD with swift?

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

982 Views

To use MBProgressHUD in swift we first need to create a podfile if it does not exist already.Go to terminal and change directory to your project directory then initialize pod and later install MBProgressHUD.cd /projectDirectory pod init open podfileThen in the podfile add the following line and go back to the terminal and run the below command in the same directory.pod 'MBProgressHUD', '~> 1.1.0' pod installOnce you run these commands MBProgressHUD will be installed to your project, now you can import this library in ViewController where ever you want to use, or you may create an extension of UIView controller ... Read More

Can I change the size of UIActivityIndicator in Swift?

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

521 Views

It is possible to change the size of UIActivityIndicator in swift using some tricks but it’s not recommended to change the size. To change the size of activity indicator let’s first add an indicator on an empty screen and see how it looks. For this example, I’ll also change the color to red.Let’s see how it looks when we run it without changing the size of the indicator.Now, we’ll create an outlet of activity indicator in our view controller and in the viewDidLoad method of this class we’ll add the code below.We’ll use CGAffineTransform to change the scale of our ... Read More

Check if string contains another string in Swift

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

252 Views

To check if a string contains another string in swift, we’ll need two different strings. One string that we have to check if it consists another string.Let us say the string we want to check is “point” and the whole string is “TutorialsPoint” and another string is “one two three”. Let’s check with both these string in the playground.We can do this in two ways as shown below. Let’s start by creating three different strings.var CompleteStr1 = "Tutorials point" var completeStr2 = "one two three" var stringToCheck = "point"Method OneIn this method we’ll use the .contains method of Strings to ... Read More

How to set target and action for UIBarButtonItem at runtime?

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

860 Views

To create a bar button action at run time we’ll need to go through a few steps. First of all let’s start by creating a new project.Once you have created the project, go to it’s storyboard directly, select the ViewController and Embed it into a navigation controller.Now go to the respective View controller class and inside it, we’ll perform some steps that will add a button to the navigation bar on run time.Create an objc function that should be called when the button is pressed.@objc func barButtonAction() {    print("Button pressed") }Now add the viewWillLayoutSubviews method to your class.First, we’ll ... Read More

Push segue from UITableViewCell to ViewController in Swift

Samual Sam
Updated on 30-Jun-2020 05:50:40

569 Views

To create a segue from a UITableViewCell to another View controller, we’ll do it like any other ViewController to ViewController segue. We’ll do this with help of an example here.First Create a project, delete the View Controller from storyboard and add One Table View Controller and one View Controller in the storyboard.There will be one prototype cell in the Table View Controller by default. Click on it, go to its attribute inspector and give it “cell” as Identifier.Now from the prototype cell, press control and drag to the Second View Controller and select show from there.The storyboard should look like ... Read More

How to integrate PayU Money in iOS using swift?

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

214 Views

payU money is a payment gateway which is more popular in Indian online markets. To Integrate payU money we need to go through a few steps. Be careful with integrating payU and do not skip any of the steps of integration.Sign Up with payU money.Once you sign up, your key & salt, merchant ID will be generated which can be found in the dashboard after you login to your payU money account.After that in the terminal application, use the below code to clone payU money.Drag and drop the PlugNPlay folder to your project.$ git clone --recursive https://github.com/payu-intrepos/PayUMoney-IOS-SDK.gitNote − If you ... Read More

Capture picture from iOS camera using Swift

Samual Sam
Updated on 30-Jun-2020 05:35:25

3K+ Views

To capture pictures from a camera in swift we can use AVFoundation which is a framework in iOS SDK, but we should try to avoid using it until we need a lot of custom features in our camera application. In this example, we’ll only capture a picture from the camera and display it on the view. We’ll be using image picker in this example instead of AVFoundation.First, create a project and add an image view on its view Controller in the storyboard. Create the outlet in its class. Now inside the ViewController class conform it to −class ViewController: UIViewController, UIImagePickerControllerDelegate, ... Read More

How to access RESTFul services from iOS/iPhone?

karthikeya Boyini
Updated on 30-Jun-2020 05:43:40

86 Views

To access REST APIs in swift we need to go through a series of steps using the native way of networking in swift, that is using URL sessions and Data Tasks.Rest stands for Representational State Transfer, which defines some set of constraints that are to be used by web services. In swift, we can access web services in the following way.First of all, we need to create a session object, which default configuration.let configuration = URLSessionConfiguration.default let session = URLSession(configuration: configuration)Then we need to create an URL Request of The type we need, it can get, post, delete or put. ... Read More

Advertisements