Found 2041 Articles for Mobile Development

Exact Radius and Size of iPhone App Icons

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

459 Views

Every iPhone application needs some icons that are displayed when certain events occur, like when some new notification comes, or the icon for home screen or the icon that is displayed on spotlight.All these icons have different size properties but apart from their size there are some common properties they have. Let’s see them first.The icons should be in .png formatThe icons should be flat and should not have transparency.The images should be squared, without any round corners.For any iOS device the icons size for app store is 1024px * 1024pxOther app icon sizes are usually bases on 1x, 2x ... Read More

How to draw a route between two locations using MapKit in Swift?

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

718 Views

To draw a route between two Locations on map we need to have co-ordinates of both those locations.Once we have the co-ordinates of both locations we can use the below given function to show the line between two points on map. In this example I’ll be using two random location as two points.func getDirections(loc1: CLLocationCoordinate2D, loc2: CLLocationCoordinate2D) {    let source = MKMapItem(placemark: MKPlacemark(coordinate: loc1))    source.name = "Your Location"    let destination = MKMapItem(placemark: MKPlacemark(coordinate: loc2))    destination.name = "Destination"    MKMapItem.openMaps(with: [source, destination], launchOptions: [MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving]) }We’ll call this function in ViewDidLoad for this tutorial to show the ... Read More

How to programmatically add a UISegmentedControl to a container view?

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

2K+ Views

To add a UISegmentControl in iOS with swift we’ll have to first create a segment control and it’s controller function, i.e. it’s action. Let’s see those steps.Let’s create a function to add a segmented control.func addControl() {    let segmentItems = ["First", "Second"]    let control = UISegmentedControl(items: segmentItems) control.frame = CGRect(x: 10, y: 250, width: (self.view.frame.width - 20), height: 50) control.addTarget(self, action: #selector(segmentControl(_:)), for: .valueChanged) control.selectedSegmentIndex = 1 view.addSubview(control) }This function may be called in our view controller to add the segmented control, let’s add action for ... Read More

How to change a button background color using Swift?

Rishi Rathor
Updated on 29-Jun-2020 14:06:03

4K+ Views

To change the background color of a button in iOS application we need to access the property ‘ backgroundColor’ of the UIButton. We can do this in two ways, programmatically and using the storyboard.Method 1 − Using the storyboard editorAdd a button on your storyboard, select it Go to it’s attribute inspector and select 'Background' property to choose the color.Method 2 − Programmatically changing the backgroundCreate outlet of the button on the View Controller.In the viewDidLoad() or viewWillLayoutSubview() method add the code to change the background color.btn.backgroundColor = #colorLiteral(red: 0.4392156899, green: 0.01176470611, blue: 0.1921568662, alpha: 1)When we run the method ... Read More

How to open and close a PDF file using Swift?

Anvi Jain
Updated on 30-Jul-2019 22:30:24

496 Views

In this article we’ll see how to open a pdf file using swift in iOS. Here we’ll do it with an example of opening pdf in webView in iOS. Let’s create a project and add WKWebView to the storyboard.Connect it’s outlet to the ViewController class.Now we’ll see two different thingsOpening a PDF file from a URL on the web.To open a web view from a url, first we need to have a url with a pdf file. In this example I’ll be using a dummy URL https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdfLet’s create a URL first, let url: URL! = URL(string: "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf")Now the remaining steps ... Read More

How to make iPhone vibrate using Swift?

Anvi Jain
Updated on 30-Jul-2019 22:30:24

1K+ Views

To make an iPhone vibrate using swift we’ll use two different methods. First create a new project and add Four different buttons to the main View controller.Now import the AudioToolbox framework in your view controller class.For the first button add an action and write the following code as shown below:@IBAction func actionButtonOne(_ sender: Any) {    AudioServicesPlayAlertSound(SystemSoundID(kSystemSoundID_Vibrate)) }This will generate a long vibrating feedback on your device. Now to create more vibration effects on devices with iOS 10 or more we’ll add methods for all four different buttons.@IBAction func actionButtonTwo(_ sender: Any) {    let generator = UIImpactFeedbackGenerator(style: .heavy)   ... Read More

How to replace a character in Objective-C String for iPhone SDK?

Vrundesha Joshi
Updated on 29-Jun-2020 14:06:41

684 Views

To replace a character in objective C we will have to use the inbuilt function of Objective C string library, which replaces occurrence of a string with some other string that we want to replace it with.To create a string in objective C we need to write −NSString *str = @"tutori@als";Now we have a choice of replacing characters in this string and creating new one, or modify this same string. In this example we will modify this string and print in the next line.str = [str stringByReplacingOccurrencesOfString:@"@" withString:@""]; NSLog(@”%@”, str);When we run the above code, str is replaced with “tutorials” ... Read More

How add 1 day to Date in swift?

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

9K+ Views

To 1 day to a date in swift we need to create a date first. Once that date is created we have to add specific days to it. In this example we’ll see how we can achieve the same.Let’s create a date first, let it be today, let today = Date()Now to modify this date we’ll use the add function with negative value, let modifiedDate = Calendar.current.date(byAdding: .day, value: 1, to: today)!Now to see the difference between both the dates, let’s add print statement for both of these. Our complete code should now look like this.let today = Date() print(today) ... Read More

How to download a video using a URL and save it in an photo album using Swift?

Jennifer Nicholas
Updated on 29-Jun-2020 14:07:25

2K+ Views

To download a video from a URL in swift we need to perform a few steps while keeping a few things in mind.Points to be noted here are, We’ll be making use of internet to download video, hence we need to allow permissions for App transport security in our Info.plistWe’ll need to save the downloaded video to Photos app, hence photos permission is required.Video should always be downloaded in background as it may prevent us from using the app if downloaded on foreground.Now, we’ll use the below code to save a video from a random link in our Device. You’ll ... Read More

How to Add Live Camera Preview to UIView in Swift?

Anvi Jain
Updated on 30-Jul-2019 22:30:24

596 Views

To add a live camera preview to our default UIView in swift we can either use AVFoundation framework of iOS SDK or native UIImagePickerController(). In this example we’ll be using ImagePicker as our aim is to present camera preview on the UIView and Imagepicker is suitable for that task. AVFoundation can be used when we need a lot of customization on our camera or different types of custom actions.To show a camera preview on the UIView we need to perform the following steps.Create a UIImagePickerController object.Conform our class to UIImagePickerControllerDelegate and UINavigationControllerDelegate.Assign delegates to the object we created in step ... Read More

Advertisements