Tint UIButton and UIBarButtonItem

Tint UIButton and UIBarButtonItem

Since iOS 5.0, UIButton and UIBarButtonItem have a tintColor property.


You may have noticed that the tint property is not available for UIButton and UIBarButtonItem.

Two common techniques to change the color, you can find around are drawing button with CoreGraphic or using a stretchable UIImage.

Lately, I found a new technique based on UISegmentedControl which you can use the tint property to change the color of your button. This control can be tweaked to have only one segment with a UIButton style (UISegmentedControlStyleBar).

Continuar leyendo «Tint UIButton and UIBarButtonItem»

A Closer Look at Table-View Cells


A table view uses cell objects to draw its visible rows and caches those objects as long as the rows are visible. These objects inherit from the UITableViewCell class. The table view’s data source provides the cell objects to the table view by implementing the tableView:cellForRowAtIndexPath: method, a required method of the UITableViewDataSource protocol. The following sections describe the characteristics of table-view cell objects, explain how to use the default capabilities of UITableViewCell for setting cell content, and show how to create custom UITableViewCell objects.


Continuar leyendo «A Closer Look at Table-View Cells»

UITableViewCell Dynamic Height

UITableViewCell Dynamic Height

At first glance setting a height dynamically for table view cells seems a little daunting and the first most obvious answers that come to mind are not necessarily correct. In this post I will show you how to set your table view cell heights dynamically based upon the text content without subclassing UITableViewCell. You can subclass it, however, doing so does not make the code much cleaner as setting the height is done in your delegate for the table view itself rather than the cell anyhow. Read on to see what you need to know to make dynamic cell height sizing a breeze. There are probably numerous reasons why you might want dynamic heights for your table view cells, but the one I’ve run into most is the need to resize because I am displaying lists of text objects with varying lengths. When the text is short, it might fit in the normal cell label, however, if the text gets longer, you will want to resize the cell so that you can display the complete content. I’ve distilled the process of resizing table cells to a few rules of thumb. Here they are:

  • Create, configure, and add a UILabel as a subview of the contentView in the cell.
  • Calculate the height in the UITableView delegate method, – (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
  • Calculate the frame for the UILabel in the UITableView delegate method, – (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

I am going to cover each of these rules in detail, but take a look at the output of the example project in the screenshot.

Continuar leyendo «UITableViewCell Dynamic Height»

Disabling the ARC in Xcode 4.2

Disabling the ARC in Xcode 4.2

With Xcode 4.2 (iOS 5) Apple introduce ARC (Automatic Reference Counting) to help with memory management. Basically you no longer need to call retain or release. However current examples/books (and (open source) libraries) are still doing it. This leads to (annoying) errors like:

ARC forbids explicit message send of ‘retain’

To get rid of this error you need to disable ARC, but how? I found this link which show how to disable it for cetain source files, but I wanted this to be a global setting.

My Kaazing colleague Richard Clark told me how to turn off ARC at the project level. Here is what you need to do in Xcode:

  1. Select your project file.
  2. You should be in the “Build settings” tab. Select the “levels” option (default is “Combined”)
  3. There’s a search field to the right of “Combined”. Enter “Automatic”
  4. Second group should be “Apple LLVM Compiler 3.0 – Language”. Second line under that controls ARC.
  5. Click that line, then in the middle column (where it says “yes”), click and choose “no”.
Now the error is gone. Great!
Thanks Richard

In-App Purchases en iOS # Parte II #


En la primera parte se vió una introducción a las In-App Purchases, categorías y tipos. Ahora veremos un ejemplo práctico, en concreto, desarrollaremos una aplicación que comprará un archivo de audio (In-App) que no se encuentra en el bundle. Una vez comprada y descargada, podremos reproducirla en nuestro dispositivo.

Continuar leyendo «In-App Purchases en iOS # Parte II #»