Understanding Self Sizing Cells and Dynamic Type in iOS 8

In iOS 8, Apple introduces a new feature for UITableView known as Self Sizing Cells. To me, this is seriously one of the most exciting features for the new SDK. Prior to iOS 8, if you want to display dynamic content in table view with variable height, you would need to calculate the row height manually. Now with iOS 8, Self Sizing Cell provides a solution for displaying dynamic content. In brief, here are what you need to do when using self sizing cells:

  • Define auto layout constraints for your prototype cell
  • Specify the estimatedRowHeight of your table view
  • Set the rowHeight of your table view to UITableViewAutomaticDimension

If we express the last two points in code, it looks like this:

1
2
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension

With just two lines of code, you instruct the table view to calculate the cell’s size matching its content and render it dynamically. This self sizing cell feature should save you tons of code and time. You’re gonna love it.

self-sizing-cell-featured
[Read more...]

Introduction to UIAlertController, Swift Closures and Enumeration

Among all the changes in iOS 8 SDK, the changes of two commonly-used APIs in UIKit framework are less known. Both UIActionSheet and UIAlertView classes are now replaced by the UIAlertController class.

In iOS 8, whenever you want to display an alert message in your app, you should use UIAlertController instead the two deprecated classes. The action sheet and alert view become the style of the UIAlertController. You choose one of the styles when creating an alert controller. The way to handle button action is redesigned. You no longer use delegate (e.g. UIAlertViewDelegate) to handle user response. When using UIAlertController, you associate actions with the controller and that the action is expressed as a block in Objective-C or closures in Swift.

In this tutorial, I’ll give you an introduction to the UIAlertController and cover how to use the class to present an alert message, as well as, an action sheet. On top of that, I’ll take this opportunity to cover the basics of closures and enumeration in Swift.

UIAlertController Introduction

Okay, let’s get started.
[Read more...]

iOS Programming 101: Implementing Pull-to-Refresh and Handling Empty Table

In this iOS Programming 101 post, I would like to answer two common questions raised by our readers.

  1. I follow your table view tutorial to create my first app. The tutorial is great. It shows us how to display data in the table view. But what if the table is empty? When there is no data, the app should display a friendly message instead of just display empty rows. How can I do that?
  2. I like the pull-to-refresh gesture. It’s a great way for content update. How can I implement such feature in my table-based app?

    Let us first take a look at the first question and see how to display a text message when the table is empty. The UITableView class includes the backgroundView property, which is the background view of the table view. This property is set to nil by default. To display a message or an image when the table is empty, usually we configure this property and set it to our own view.

    uirefreshcontrol featured
    [Read more...]

A Beginner’s Guide to Optionals in Swift

Swift was announced three weeks ago. Since then, I have been reading the Swift’s official guide and playing around with it in Xcode 6 beta. I started to love the simplicity and syntax of Swift. Along with my team, I am still studying the new language and see how it compares with Objective-C, a 30-year-old programming language. At the same time, we’re working really hard to see how we can teach beginner and help the community to pick up Swift effortlessly.

Two weeks ago, we covered the basics of Swift. In coming weeks, we’ll write a series of tutorials to cover a number of new features in Swift. This week, let’s first take a look at optionals.

swift-optionals-featured

[Read more...]

Getting Started with Swift: A Brief Intro to the New Programming Language

Along with the announcement of iOS 8 and Yosemite, Apple surprised all developers in the WWDC by launching a new programming language called Swift. At AppCoda, we’re all excited about the release of Swift. We enjoy programming in Objective-C but the language has showed its age (which is now 30 years old) as compared to some modern programming languages like Ruby. Swift is advertised as a “fast, modern, safe, interactive” programming language. The language is easier to learn and comes with features to make programming more productive. It seems to me Swift is designed to lure web developers to build apps. The syntax of Swift would be more familiar to web developers. If you have some programming experience with Javascript (or other scripting languages), it would be easier for you to pick up Swift rather than Objective-C.

If you’ve watched the WWDC keynote, you should be amazed by an innovative feature called Playgrounds that allow you to experiment Swift and see the result in real-time. In other words, you no longer need to compile and run your app in the Simulator. As you type the code in Playgrounds, you’ll see the actual result immediately without the overheads of compilation.

swift-playground

At the time of this writing, Swift has only been announced for a week. Like many of you, I’m new to Swift. I have downloaded Apple’s free Swift book and played around with Swift a bit. Swift is a neat language and will definitely make developing iOS apps more attractive. In this post, I’ll share what I’ve learnt so far and the basics of Swift.
[Read more...]

First Time App Developer Success Stories Part 3: Am I Too Late to Learn iOS Programming

Am I too late to start learning iOS programming? Simply do a search on Google or Quora. You’ll see lots of discussions around the web. The mobile market has created tons of opportunities and possibilities. It’s amazing you can turn an idea into app that millions of people use. I’ve met a lot of people who love to create apps but think coding is difficult and it’s too late for them to learn to code.

It’s never to late. It’s the lack of determination and drive that keep you from learning programming. Some time ago, we shared the first and second parts of app developer stories. In part 3 of the series, we featured even more app developers to share their success stories. The ages of these first-time app developers range from 15 to 68 years old. Yes, you read it right. Robert Chalmers, one of the featured developers, is 68 years old! Though Robert got years of experience, it’s amazing he still keeps learning new programming language. I couldn’t imagine if I would still learn programming at that age. Rémy Spehler, who is a doctor by profession, started from zero programming experience to published his first app at the age of 58. The design of their apps is elementary and may not catch your attention. But they set a great example showing that everyone can learn iOS programming and build apps regardless of age.

first-time-app-showcase-3

I haven’t highlighted all the developers here but all of the stories are truly inspiring. Read on and check out their success stories.

[Read more...]

iOS Programming 101: How To Create Swipeable Table View Cell to Display More Options

When iOS 7 was first released, one of the many visual changes that particularly interested me was the swipe-to-delete gestures in the Mail app. By now you should be very familiar with the feature. After you swipe a table cell, you’ll see the Trash button, plus a new button named More. The More button will bring up an action sheet that shows a list of options such as Reply, Flag, etc.

I thought it’s a great feature to provide additional options for manipulating a table record. However, as you know, Apple didn’t make this feature available to developers in iOS 7. You can only create the swipe-to-delete option in table cell. The More feature is only limited to the stock Mail app. I have no idea why Apple keeps such great feature to its own app. Fortunately, some developers have created free solutions (such as UITableView-Swipe-for-Options, MCSwipeTableViewCell) and made them available freely.

In this tutorial, I’ll use SWTableViewCell and see how to implement swipe-to-show-options feature in your app. SWTableViewCell is pretty to easy to use. If you understand how to implement UITableView, you shouldn’t have any problem with SWTableViewCell. On top of that, it supports utility buttons on both swipe directions. You’ll understand what it means in a minute.

Swipeable UITableViewCell

Let’s get started and build our demo app.
[Read more...]

First Time App Developer Success Stories Part 2: From Zero iOS Programming Experience to Launching Their First Apps

You may have read some app millionaire stories that earn tons of money overnight. But you rarely find stories about app developers who are less successful. Recently I reached out to a number of first time app developers and asked them to share their app development experience. To me their stories are equally amazing and I have learnt so much from them. These developers are all started from zero iOS programming experience and end up with their apps launched on App Store. A couple weeks ago I shared the first part of the success stories. Here comes to the part 2.

Some people think it’s hard to create their first apps because they get a big idea. Most of them only see the “million-dollar ideas” and want to hit big when the app launches. That’s unreal and you’ll easily get frustrated if your expectation is too high. The truth is you don’t need to have a grand idea and set high expectation when first started. The developers featured in this post just started small and built their first apps around a simple idea they cared about, be it a recipe app or a game book.

Once again, I’m really proud to showcase their works. Enjoy their stories and app development experience. If you’re still struggled about how to learn iOS programming and make your first app, you’ll probably inspired by their stories.

app-developer-part-2
[Read more...]

iOS Programming 101: How To Create Circular Profile Picture and Rounded Corner Image

One of the changes in iOS 7 is that it favors the use of circular image over square image. You can find circular icons or images in stock apps such as Contacts and Phone. In this short post, we’ll explore the CALayer class and see how you can apply it to create circular image or image with rounded corner.

You may not heard of the CALayer class. But you should have used it in some ways if you’ve built an app. Every view in the UIKit (e.g. UIView, UIImageView) is backed by an instance of the CALayer class (i.e. layer object). The layer object is designed to manage the backing store for the view and handles view-related animations.
The layer object provides various attributes that can be set to control the visual content of the view such as:

  • Background color
  • Border and border width
  • Shadow color, width, etc
  • Opacity
  • Corner radius

The corner radius is the attribute that we’ll use to draw rounded corner and circular image.

Circular Image using calayer

As always, the best way to understand how CALayer works is to use it. We’ll create a simple profile view with a circular profile photo.

[Read more...]

First Time App Developer Success Stories Part 1: From Zero iOS Programming Experience to Launching Their First Apps

“I got a great idea and want to build an app!”

How many times have you heard of this? I heard quite a lot. But only a few people fire up Xcode and take action to build their own apps. Most of them may just say,

“Programming is too difficult for me!”

“I do not have time to learn programming!”

“Let me finish X first and wait for some day to start building my apps.”

These first time app developers featured in this post are those who put the hard work in and turn their idea into real apps. Above all, they are committed to take action. When they first get started, most of them do not have any prior programming experience. They learnt iOS programming by following the materials in our iOS programming book or tutorials in the iOS programming course, as well as, other resources available online.

first-time-app-showcase-1

Their apps may not attract millions of downloads or make tons of money. But to me, as someone who teaches, all the first apps covered here are a great success. I’m really proud to showcase their works. Enjoy their stories and app development experience.
[Read more...]