- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2041 Articles for Mobile Development
2K+ Views
To detect the end of a video in swift we’ll need to create a video player, then use notifications to detect when the video stops playing. We’ll do this with help of an example in swift.Let’s create a project and drag and drop any video with extension “mp4”, select copy resource if required and add to the target of our project.Now we’ll programmatically first create a Video Player, then we’ll create url of the video in our project, and then we’ll play the video.var videoPlayer: AVPlayer!Now, in the viewDidAppear add the following code.override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) ... Read More
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
739 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
987 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
522 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
255 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
869 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
571 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
1K+ Views
There are so many cases, it required to show password while entering password or after entered password. This example demonstrate about How to switch between hide and view password.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml. In the above code we have given two TextInputEditText ... Read More
2K+ Views
There are so many situations where we don't required keyboard visibility when activity starts. This example demonstrate about how to Stop EditText from gaining focus at Activity startupStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/Activity_main.xml. In the above code, we have given on Edit Text. By Default it contains request focus.Step 3 − Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.EditText; public class MainActivity extends ... Read More