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:
addTextFieldWithValue:label:
textFieldAtIndex:

“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;@”mailto:myname@gmail.com?subject=Hello&body=Hi”];
[[UIApplication sharedApplication] openURL:url];

Email with HTML formatting:

NSString *emailBody = @”<table>
<tr><td style=’text-align:right’><b>FirstName</b>:</td>
<td>Michael</td></tr><tr>
<td style=’text-align:right’><b>LastName</b>:</td><td>Jackson</td></tr>
<tr><td style=’text-align:right’>
<b>Job<b/>:</td><td>Artist</td></tr></table>”;
NSString *encodedBody =
[emailBody stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString =
[NSString stringWithFormat:@”mailto:myname@gmail.com?subject=Hello&body=%@”, encodedBody];
NSURL *url = [[NSURL alloc] initWithString:urlString];
[[UIApplication sharedApplication] openURL:url];

iPhone simulator does not have a Mail.app. 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.

#if TARGETIPHONESIMULATOR
    //compiler specific code
#else
    // device specific code
#endif

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)
  • IMA4 (IMA/ADPCM)
  • 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)
  • IMA/ADPCM (IMA4)
  • 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;
@end

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;
@end

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];
}

Vector-Based JavaScript

July 3, 2009 § Leave a comment

Raphaël is a JavaScript library that simplify your vector graphics.

It uses SVG W3C and VML standard to create graphics. Each graphical object you carete is a DOM object that you can attach JavaScript event handlers or modify them later.

The advantages are to make drawing vector art compatible cross-browser. It supports Firefox 3.0+, Safari 3.0+, Opera 9.5+ and Internet Explorer 6.0+.

// Creates canvas 320 × 200 at 10, 50
var paper = Raphael(10, 50, 320, 200);
// Creates circle at x = 50, y = 40, with radius 10
var circle = paper.circle(50, 40, 10);
// Sets the fill attribute of the circle to red (#f00)
circle.attr("fill", "#f00");
// Sets the stroke attribute of the circle to white (#fff)
circle.attr("stroke", "#fff");

iPhone Opensource Core Plot Framework

July 1, 2009 § 1 Comment

Apple SDK doesn’t come with any Graph framework. Core-plot is one of the rare opensource plotting framework for iphone. It provides 2D visualization of data, and is tightly integrated with Apple technologies like Core Animation, Core Data, and Cocoa Bindings.

Core Plot is based on Core Animation. You have to add QuartzCore framework to Xcode project.

A detail tutorial on how to integrate Core Plot framework to your Xcode project is here.

Add this line to the porject:
#import “CorePlot-CocoaTouch.h”

First, drag the CorePlot-CocoaTouch.xcodeproj file into your iPhone application’s Xcode project (making sure that nothing’s copied and the paths are relative to your project). Then go to the Targets tab in Xcode, select your application’s target, and bring up the inspector. Go to the General settings page and add the CorePlot-CocoaTouch library as a direct dependency.

Core Plot is built as a static library for iPhone, so you’ll need to drag the libCorePlot-CocoaTouch.a static library from under the CorePlot-CocoaTouch.xcodeproj group to your target’s Link Binary With Libraries folder.

You’ll also need to point to the right header location. Under your Build settings, set the Header Search Paths to the relative path from your application to the framework/ subdirectory within the Core Plot source tree. Make sure to make this header search path recursive. You need to add -ObjC to Other Linker Flags as well.

References:
Google Plot API
Weight Diary Plot framework

Google Map API Performance

June 30, 2009 § 2 Comments

I am summarizing a session on Google Map API Performance here. This help you to evaluate using Google Map for iphone app.

Google JavaScript Map API

The total sequence of loading the script and resources is about 4.6 sec on avg web. However, it takes 18 sec to load on Android and iphone.

JavaScript library is 220 KB unzipped. It takes more than 4 sec to parse the API on iphone. Since engineers can’t reduce the codebase size after modularizing classes, Google map team decides to create Google Map API v3.

This v3 offers a few features – markers, infowindows, geocoding.

On v2 GMarker class is designed for features not for performance. Each marker is consisting of up to 5 divs. To show 10,000 GMarkers, you are loading 50,000 DOM nodes in the browser.

Google extends GOverlay class to create a custom lightweight marker. This MakerLight, overlay contains only 2 divs per marker.

Google Flash API is faster in rendering but it suffers from a slow DOM.

Where Am I?

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