Adding Text Field inside UIAlertView

February 18, 2011 § Leave a comment

Adding form text field into an alert window on iOS is a popular UI pattern. It’s a very handy feature to achieve good user experience by asking a simple input without any click on the same screen. The best use is iPhone app to ask for user password and to log into iTunes app store for app purchase.

To add a form text field inside UIAlertView is tricky. Technically it is easy. However Apple reserves the right to use Private API for its own native app design. Developer would have to work more in order to achieve the same feature.

If you use these Objective-C methods to insert a Text Field inside UIAlert, your app will get rejected by Apple review team.

The following non-public APIs are included in your application:

“3.3.1 Applications may only use Documented APIs in the manner prescribed by Apple and must not use or call any private APIs.”

I’ll share how to add Text Field without using these private API methods.

Sending email without and with HTML formatting in Objective-C

November 16, 2009 § Leave a comment

This is the standard of sending email in Objective-C iPhone App.

Use a mailto url + stringByAddingPercentEscapesUsingEncoding + HTML.

Simple Email without any sentences or any HTML formatting:

NSURL *url = [[NSURL alloc] initWithString;@””];
[[UIApplication sharedApplication] openURL:url];

Email with HTML formatting:

NSString *emailBody = @”<table>
<tr><td style=’text-align:right’><b>FirstName</b>:</td>
<td style=’text-align:right’><b>LastName</b>:</td><td>Jackson</td></tr>
<tr><td style=’text-align:right’>
NSString *encodedBody =
[emailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString =
[NSString stringWithFormat:@””, encodedBody];
NSURL *url = [[NSURL alloc] initWithString:urlString];
[[UIApplication sharedApplication] openURL:url];

iPhone simulator does not have a You can only email url in device. However, you can consider to use compiler statements to create specific simulator/device code. You can use UIAlertView to preview the email string. Consider using UITextView to preview the text and UIWebView to preview HTML in the simulator.

    //compiler specific code
    // device specific code

iPhone Objective-C Adding UITextView upon viewDidLoad

November 10, 2009 § 2 Comments

This is a simple approach to draw a UITextView, insert content from a text file within Xcode project, disable editing, and customize font style during loading app.

– (void)viewDidLoad {

[super viewDidLoad];
CGRect viewRect = CGRectMake(0.0, 0.0, 320.0, 420.0);
myTextView = [[UITextView alloc] initWithFrame:viewRect];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filename = [documentsDirectory stringByAppendingPathComponent:@”sample.txt”];
NSString *filenameString = [NSString stringWithContentsOfFile:filename];
myTextView.text = filenameString;
myTextView.editable = NO;
myTextView.textAlignment = UITextAlignmentCenter;
UIFont *myFont = [UIFont fontWithName:@”Helvetica” size:10.0];
// add Font color
myTextView.font = myFont;
[self.view addSubview:myTextView];

Nokia Mobile HTML Templates

November 2, 2009 § Leave a comment

Nokia just open source their mobile HTML templates for high-end, mid-range, and low-end phones. It includes templates and layout samples with content.

It includes HTML, CSS, Photoshop & Illustrator templates. It is a good starting point for Nokia beginner developers.

The high-end templates include components optimised for touch devices (S60 5th Edition and Maemo), and components optimised for Series 40 and S60 WebKit non-touch devices.

The mid-range templates include pre-styled mobile web elements optimised for a large collection of Series 40 devices from Series 40 3rd to Series 40 6th Edition.

The low-end templates include pre-styled mobile web elements optimised for a large collection of early S60 and Series 40 devices.

Supported Audio Formats in Playback & Recording

July 7, 2009 § 2 Comments

Supported Audio Playback formats:

  • AAC
  • HE-AAC
  • AMR (Adaptive Multi-Rate, a format for speech)
  • ALAC (Apple Lossless)
  • iLBC (internet Low Bitrate Codec, another format for speech)
  • linear PCM (uncompressed)
  • µ-law and a-law
  • MP3 (MPEG-1 audio layer 3

Supported Audio Recording Formats:

  • ALAC (Apple Lossless)
  • iLBC (internet Low Bitrate Codec, for speech)
  • linear PCM
  • µ-law and a-law

AAC, MP3, and ALAC (Apple Lossless) Playback for AAC, MP3, and ALAC sounds can use efficient hardware-based decoding on iPhone OS–based devices, but these codecs all share a single hardware path. The device can play only a single instance of one of these formats at a time through hardware. If the user is playing a sound in one of these three formats in the iPod application, then your application—to play along over that audio—will employ software decoding. AAC, ALAC, MP3 can employ hardware decoding for playback.

Linear PCM and IMA4 (IMA/ADPCM You can play multiple linear PCM or IMA4 sounds simultaneously in iPhone OS without incurring CPU resource problems. It is same for the AMR and iLBC speech-quality formats, and for the µ-law and a-law compressed formats.

The device can play only a single instance of one of these formats at a time through hardware. For example, if you are playing a stereo MP3 sound, a second simultaneous MP3 sound will use software decoding. Similarly, you cannot simultaneously play an AAC and an ALAC sound using hardware. If the iPod application is playing an AAC sound in the background, your application plays AAC, ALAC, and MP3 audio using software decoding.

To play multiple sounds with best performance, or to efficiently play sounds while the iPod is playing in the background, use linear PCM (uncompressed) or IMA4 (compressed) audio.

SDK 3.0 Upgrades on AVFoundation Framework

July 7, 2009 § Leave a comment

SDK 3.0 has added the following APIs in AVFoundation framework

  • AVAudioRecorder.h
  • AVAudioSession.h
  • AVAudioSettings.h

Existing APIs in SDK 2.2.1:

  • AVAudioPlayer.h
  • AVFoundation.h

Upgrade in Utility App from SDK 2.2.1 to SDK 3.0

July 7, 2009 § 1 Comment

In SDK 2.2.1, infoButton is just a UIButton that is controlled by the toggleView: method in RootViewController.h.

SDK 3.0 reveals a new architecture. RootViewController .h & .m files are eliminated from the directory of “Application Delegate”. <FlipsideViewControllerDelegate> and showInfo: method are added to the MainViewConroller .h file.

New architecture in SDK 3.0 is a better implementation because it eliminates the complexity of RootViewController. It is complicated to pass data between MainViewController and FlipsideViewController via the middleman, RootViewController.

In SDK 2.2.1 RootViewController.m:

#import <UIKit/UIKit.h>
@class MainViewController;
@class FlipsideViewController;
@interface RootViewController : UIViewController {
UIButton *infoButton;
MainViewController *mainViewController;
FlipsideViewController *flipsideViewController;
UINavigationBar *flipsideNavigationBar;
@property (nonatomic, retain) IBOutlet UIButton *infoButton;
@property (nonatomic, retain) MainViewController *mainViewController;
@property (nonatomic, retain) UINavigationBar *flipsideNavigationBar;
@property (nonatomic, retain) FlipsideViewController *flipsideViewController;
– (IBAction)toggleView;

In RootViewController.m:

– (IBAction)toggleView {
This method is called when the info or Done button is pressed.
It flips the displayed view from the main view to the flipside view and vice-versa.
if (flipsideViewController == nil) {
[self loadFlipsideViewController];
UIView *mainView = mainViewController.view;
UIView *flipsideView = flipsideViewController.view;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];
if ([mainView superview] != nil) {
[flipsideViewController viewWillAppear:YES];
[mainViewController viewWillDisappear:YES];
[mainView removeFromSuperview];
[infoButton removeFromSuperview];
[self.view addSubview:flipsideView];
[self.view insertSubview:flipsideNavigationBar aboveSubview:flipsideView];
[mainViewController viewDidDisappear:YES];
[flipsideViewController viewDidAppear:YES];
} else {
[mainViewController viewWillAppear:YES];
[flipsideViewController viewWillDisappear:YES];
[flipsideView removeFromSuperview];
[flipsideNavigationBar removeFromSuperview];
[self.view addSubview:mainView];
[self.view insertSubview:infoButton aboveSubview:mainViewController.view];
[flipsideViewController viewDidDisappear:YES];
[mainViewController viewDidAppear:YES];
[UIView commitAnimations];

In SDK 3.0 MainViewController.h:

#import “FlipsideViewController.h”
@interface MainViewController : UIViewController <FlipsideViewControllerDelegate> {
– (IBAction)showInfo;

In MainViewController.m:
– (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller {
[self dismissModalViewControllerAnimated:YES];
– (IBAction)showInfo {
FlipsideViewController *controller = [[FlipsideViewController alloc] initWithNibName:@”FlipsideView” bundle:nil];
controller.delegate = self;
controller.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:controller animated:YES];
[controller release];

Where Am I?

You are currently browsing the UI Design category at Web Builders.