Skip to main content

Posts

Showing posts from June, 2018

How to Implementing Auto-Complete With UITextField - Swift

Auto-Complete Text I recently wanted to add a Safari-like auto-complete feature to an iOS app I've been working on. Specifically, I wanted the app to proactively suggest a complete word based on some initial characters entered by the user, similar to how Safari suggests URLs based on the first few letters in a web address: As in Safari, tapping Return would allow the user to confirm the suggestion. Since this is not a feature that Apple provides "out of the box," I thought I would share the approach I took in case it is of interest to anyone. In this example, the text field will suggest values for the user's fav color: As the user types, a list of options is consulted to determine which value to suggest. For example: Suggestions are defined as an array of strings: let suggestions = [ "red" , "orange" , "yellow" , "green" , "blue" , "purple" ] ...

How to Set Self-Sizing Cells with UITableView and Auto Layout - Swift

Set Self-Sizing Cells For a long time, a big challenge for iOS developers was custom heights and sizes for  UITableView  and also  UICollectionView  Cells. There were ways to achieve this such as ‘ Auto Layout ’, but they were ‘hacky’ and not fully implemented. Previously to calculate height, developers had two options. If using Auto Layout, a developer could create an offscreen cell, layout the content in  tableView:heightForRowAtIndexPath:  and then get the height (using  systemLayoutSizeFittingSize: ). If not using Auto Layout, the height had to be calculated manually for each cell and the values cached to avoid slowdown. With iOS 8,  UITableView s and  UICollectionView s have embraced Auto Layout. In this post, we will cover what you need to know to support  UITableView s in your apps. We will create a small sample application, that you can also find on  Github . ...