- Trending Categories
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 1957 Articles for Mobile Development

Updated on 30-Jul-2019 22:30:24
To create multiple styles inside a textview we need to use attributed string. The text view in ios has a property attributedText which can be used to style the text inside a text view. We’ll see this with help of an example.First, we’ll create an attributelet attributeOne : [NSAttributedString.Key : Any] = [NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue) : UIFont.systemFont(ofSize: 16.0), NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue) : UIColor.blue]Then we’ll create an attributed string with the attribute we createdlet string = NSAttributedString(string: "Text for first Attribute", attributes: attributeOne)Similarly, we’ll create another string with different attribute. Then we’ll initialize the text of textView with the attributed string.Now the whole ... Read More 
Updated on 30-Jul-2019 22:30:24
To create a scrollable TextView in iOS we can do it in two ways, one by creating it using the storyboard and other by creating another textView programmatically.A text view is scrollable by default if it has text more than the height of textView and the scrollable property is disabled.1.Using storyboardGo to storyboard and from the object library drag a textView to your view.Now in the text view if the text is more than it’s height than it will be scrollable by default, otherwise it will not be scrollable.Give height constraint along with remaining required constraint.Make sure that scrolling enabled ... Read More 
Updated on 30-Jun-2020 05:58:40
To use collection view in swift, first, we need to create a collection View. We can either drag and drop it to the storyboard, or we can make it programmatically. After that, we need to confirm our class to UICollectionViewDataSource and UICollectionViewDelegate. Also if we need custom cell size and layouts, we need to confirm it to UICollectionViewDelegateFlowLayout.Let’s see the step required to create a collection View programmatically.func initCollection() { let layout = UICollectionViewFlowLayout() layout.itemSize = CGSize(width: 50, height: 50) let collection = UICollectionView.init(frame: self.view.frame, collectionViewLayout: layout) collection.dataSource = self collection.delegate = self collection.backgroundColor ... Read More 
Updated on 30-Jul-2019 22:30:24
To give a dynamic height to an UIlabel in swift we can use the frame property of UILabel. We can create a frame using the CGRect which allows us to give different variables like x position, y position, width, and height.Let’s create a label and add it as a subview to our view.let label = UILabel() label.frame = CGRect(x: 10, y: 40, width: 200, height: 50) label.backgroundColor = colorLiteral(red: 0.7450980544, green: 0.1568627506, blue: 0.07450980693, alpha: 1) label.textColor = colorLiteral(red: 0.05882352963, green: 0.180392161, blue: 0.2470588237, alpha: 1) label.text = "Custom label" self.view.addSubview(label)We can embed this in a function as well, and ... Read More 
Updated on 30-Jun-2020 05:59:34
To remove a specific object from an element in swift, we can use multiple ways of doing it. Let’s see this in the playground with help of an example.First, let’s create an array of String.var arrayOfString = ["a", "b", "c", "f"]We’ll do it with the following methods as shown below:Method 1 − Using the filter method of the array.Arrays in swift have a filter method, which filters the array object depending on some conditions and returns an array of new objects.let modifiedArray = arrayOfString.filter { $0 != "f" } print(modifiedArray)When we run the above code, we get the following result.Method ... Read More 
Updated on 30-Jul-2019 22:30:24
To request location services permission in ios with swift we can use the CLLocationManager.We’ll do this with help of a sample project. So, create a new project. First, we need to create a locationManager object, so in your view controller.var locationManager = CLLocationManager()Now, we, first of all, we need to check if the location services are enabled on the device or not. To check this we’ll useCLLocationManager.locationServicesEnabled() function, which returns a Boolean value showing whether the location service on the device is active or not.if CLLocationManager.locationServicesEnabled() { print("permissions allowed") } else { locationManager.requestAlwaysAuthorization() locationManager.requestWhenInUseAuthorization() }In the example ... Read More 
Updated on 30-Jul-2019 22:30:24
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 
Updated on 30-Jul-2019 22:30:24
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 
Updated on 30-Jun-2020 05:49:10
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 
Updated on 30-Jul-2019 22:30:24
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 Advertisements