iOS Articles

Page 13 of 19

How to set background color of a View in iOS App?

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 2K+ Views

Views are the fundamental building blocks of your app's user interface, and the  UIView class defines the behaviors that are common to all views. A view object renders content within its bounds rectangle and handles any interactions with that content. The  UIView class is a concrete class that you can instantiate and use to display a fixed background color.It is very important to have complete understanding of UIView as they are the main object user sees.Here we will be seeing how to change the background color of view programmatically and via storyboard.First let us see using storyboard, Open Main.storyboard and ...

Read More

How do I display the current date and time in an iOS application?

Rama Giri
Rama Giri
Updated on 30-Jul-2019 314 Views

Playing with date and time is very important in any programming language, it becomes more important if you’re developing mobile application.Numerous application such as weather, forecast, gaming and so on uses date and time. In this we will be seeing how we can get the current date and time.To get the current date and time we will be using timeIntervalSince1970 instance property, you can read about it https://developer.apple.com/documentation/foundation/nsdate/1407504-timeintervalsince1970So copy the below code in your viewDidLoad method and run the application, we will be printing the current date and time, and based on requirement we can print the same in UILabel ...

Read More

How can I set an icon for my iOS application?

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 251 Views

Every app needs a beautiful and memorable icon that attracts attention in the App Store and stands out on the Home screen. Your icon is the first opportunity to communicate, at a glance, your app’s purpose. It also appears throughout the system, such as in Settings and search results.Here we will be seeing how we can set icon for iOS Application but before that we should make sure and understand that Every app must supply small icons for use on the Home screen and throughout the system once your app is installed, as well as a larger icon for display ...

Read More

How to get the current location latitude and longitude in iOS?

Kumar Varma
Kumar Varma
Updated on 30-Jul-2019 3K+ Views

Almost all the application uses location services, thus having complete understanding on location is necessary. In this post we will be seeing how to get current location’s latitude and longitude.For this we will be using CLLocationManager, you can read more about it herehttps://developer.apple.com/documentation/corelocation/cllocationmanagerWe will be developing a sample application where we will print user’s latitude and longitude on viewDidLoad method, alternatively you can print on tap of a button also on UILabel as per need.So let’s get started, Step 1 − Open Xcode → New Projecr → Single View Application → Let’s name it “Location”Step 2 − Open info.plist file ...

Read More

Set Border for an ImageView in iOS?

Mohtashim M
Mohtashim M
Updated on 30-Jul-2019 1K+ Views

Setting border for image view is easy, In this post we will see how to set Border for an Image View in iOS.Let’s get started.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “BorderToImage”We will create an image view and a button in our storyboard on tap of button we will add border to image view. We could do the same in viewDidLoad but to see the difference we’re doing this.Step 2 − In Main.storyboard add an image view and a button as shown below.Step 3 − Create @IBOutlet for image and name ...

Read More

Where and how to use static variable in swift?

Mohtashim M
Mohtashim M
Updated on 30-Jul-2019 8K+ Views

Before we see where and how to use static variable, let us first understand, What is static variable in swift?Static VariableStatic variables are those variables whose values are shared among all the instance or object of a class. When we define any variable as static, it gets attached to a class rather than an object. The memory for the static variable will be allocation during the class loading time.Let us understand above figure, we have a class Sample and it has two object s1 and s2. You see s1 and s2 both have their variable “a” separately but they have ...

Read More

How do I prevent an iOS device from going to sleep mode?

Mohtashim M
Mohtashim M
Updated on 30-Jul-2019 1K+ Views

When most apps have no touches as user input for a short period, the system puts the device into a "sleep” state where the screen dims. This is done for the purposes of conserving power.Preventing iOS Device from going to sleep is easy, navigate to your Settings → Display & Brightness → Autolock, select never.This will never lock your screen.If you’re developing an iOS Application and you’re required to implement this feature, you should use isidletimerdisabled provided by apple, to read more about it https://developer.apple.com/documentation/uikit/uiapplication/1623070-isidletimerdisabledIn your viewDidLoad method write the following line of code to prevent the device from going to ...

Read More

How to count number of characters in Text box while typing in iOS?

Mohtashim M
Mohtashim M
Updated on 30-Jul-2019 1K+ Views

As an iOS developer one should know how to manipulate with text field and it’s operation, Apple has already provided UITextFieldDelegate protocol.To read more about it https://developer.apple.com/documentation/uikit/uitextfielddelegateYou may have seen may application where forms are involved, and you see number of characters you’re entering when you type specially on the forms where characters are restricted to certain count.In this post we’re going to see the same how to display the character count, when you type in TextField.Step 1 − Open Xcode → New Project → Single View Application → Let’s name it “TextFieldCount”Step 2 − Open Main.storyboard and add TextField and ...

Read More

How to run a timer in background within your iOS app

Smita Kapse
Smita Kapse
Updated on 30-Jul-2019 2K+ Views

If you wish to run a timer in background within your iOS Application, Apple provides beginBackgroundTaskWithExpirationHandler method, you can read more about the same developer.apple.com/documentation/uikit/uiapplication/1623031-beginbackgroundtaskwithexpiration.We will be using the same for writing our code for running the timer in background.So let’s begin.Step 1 − Open Xcode → Single View Application → Let’s name is BackgroundTimer.Step 2 − Open AppDelegate.swift and under method applicationDidEnterBackground write the below code.backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: {    UIApplication.shared.endBackgroundTask(self.backgroundTaskIdentifier!) }) _ = Timer.scheduledTimer(timeInterval: 1,  target: self,  selector: #selector(self.doSomething), userInfo: nil, repeats: true)Step 3 − Write new function doSomething()@objc func doSomething() {    print("I'm running") }Finally your code should look like belowfunc applicationDidEnterBackground(_ application: UIApplication) {    backgroundTaskIdentifier = UIApplication.shared.beginBackgroundTask(expirationHandler: { ...

Read More

How to get the MAC address of an iOS/iPhone programmatically?

karthikeya Boyini
karthikeya Boyini
Updated on 30-Jul-2019 1K+ Views

In iOS versions previous to 7.0 getting the MAC address of device was possible. But with new iOS version it has been disabled for the apps to access MAC address of the device.When it is accessed or requested on current version of iOS it always returns 02:00:00:00:00:00. This has been implemented by apple because of privacy concerns. If your app needs to uniquely identify a device, apple recommends to use UDID/ UUID instead of MAC. In swift we can useUIDevice.current.identifierForVendor Which as per apple documentation says that, The value of this property is the same for apps that come from ...

Read More
Showing 121–130 of 182 articles
« Prev 1 11 12 13 14 15 19 Next »
Advertisements