Found 2041 Articles for Mobile Development

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

5K+ 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 do I change current theme at runtime in my android app?

Azhar
Updated on 03-Jul-2020 11:49:36

981 Views

This example demonstrates how do I change current theme at runtime in my android app.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.     Step 3 − Add the following code to src/MainActivity.javaimport android.support.v7.app.AppCompatActivity; import android.os.Bundle; public class MainActivity extends AppCompatActivity {    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setTheme(android.R.style.Theme_Black);       setContentView(R.layout.activity_main);    } }Step 4 − Add the following code to androidManifest.xml ... Read More

How to switch between different activities in android?

Azhar
Updated on 03-Jul-2020 10:14:05

4K+ Views

This example demonstrates how do I switch between different activities in android.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.         Step 3 − Add the following code to src/MainActivity.javaimport android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity {    Button button;    @Override    protected void onCreate(Bundle savedInstanceState) {       super.onCreate(savedInstanceState);       setContentView(R.layout.activity_main);       button = findViewById(R.id.btnOpenAct2);       ... Read More

How to create TextToSpeech in an android app?

Azhar
Updated on 03-Jul-2020 10:14:44

109 Views

This example demonstrates how do I create TextToSpeech in an android app.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.                         Step 3 − Add the following code to src/MainActivity.javaimport android.speech.tts.TextToSpeech; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.SeekBar; import java.util.Locale; public class MainActivity extends AppCompatActivity {    private TextToSpeech textToSpeech;    private EditText editText;    private ... Read More

How to play YouTube video in my Android Application?

Azhar
Updated on 03-Jul-2020 10:15:17

2K+ Views

This example demonstrates how do I play Youtube video in android.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 following the dependancies in the build.gradle (Module:app)implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.android.support:cardview-v7:28.0.0'Step 3 − Add the following code to res/layout/activity_main.xml.         Step 4 – Create a layout resource file (Video_view.xml) and add the following code − Step 5 – Create a java class youTubeVideos.java and the following code −public class youTubeVideos {    String videoUrl;    public youTubeVideos() ... Read More

Advertisements