Get 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

Prevent Scrolling in WebView of iOS Programmatically

Sadiqaadil
Updated on 11-Sep-2019 08:13:30

2K+ 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

Check If a Text Field is Empty in Swift

Sadiqaadil
Updated on 11-Sep-2019 07:57:25

4K+ 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

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

Animate Change of Background Color of a View on iOS

Sadiqaadil
Updated on 11-Sep-2019 07:47:17

2K+ 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

Upcast and Downcast the Same Object in Java

Maruthi Krishna
Updated on 11-Sep-2019 07:22:54

337 Views

Converting one data type to others in Java is known as casting.Up casting − If you convert a higher datatype to lower datatype, it is known as narrowing (assigning higher data type value to the lower data type variable).Example Live Demoimport java.util.Scanner; public class NarrowingExample {    public static void main(String args[]){       char ch = (char) 67;       System.out.println("Character value of the given integer: "+ch);    } }OutputCharacter value of the given integer: CDown casting − If you convert a lower datatype to a higher data type, it is known as widening (assigning lower data type ... Read More

Read Data from PDF File and Display on Console in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:44:22

11K+ Views

There are several libraries to read data from a pdf using Java. Let us see how to read data from a PDF document and display it on the console using a library named PDFBox.You can extract text using the getText() method of the PDFTextStripper class. This class extracts all the text from the given PDF document to use this.Load an existing PDF document using the static method load() of the PDDocument class.Instantiate the PDFTextStripper class.Retrieve.read the contents of the PDF page to a String using the getText() method of the PDFTextStripper class.Finally, close the document using the close() method of ... Read More

Calculate String Buffer Capacity in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:38:26

1K+ Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ... Read More

Replace Specific Part of String and StringBuffer in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:33:41

300 Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class.Example Live Demopublic class StringExample {    public static void main(String[] args) {       String str = new String("Hello how are you");       System.out.println("Contents of the String: "+str);    } }OutputHello how are youStrings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the ... Read More

Trim White Space in StringBuffer in Java

Maruthi Krishna
Updated on 10-Sep-2019 13:28:48

3K+ Views

The String class of the java.lang package represents a set of characters. All string literals in Java programs, such as "abc", are implemented as instances of this class. Strings objects are immutable, once you create a String object you cannot change their values, if you try to do so instead of changing the value a new object is created with the required value and the reference shifts to the newly created one leaving the previous object unused.The StringBuffer (and StringBuilder) class is used when there is a necessity to make a lot of modifications to a String.Unlike Strings, objects of ... Read More

Advertisements