Dec 7, 2010

(iOS) Available font family

A good example to list all available font family of iOS system. Check it out.

Nov 19, 2010

(iPhone)How to display different color text

There are several ways to display different color text in iOS device.
  1. Use multiple UILabel and each contains different font style.
  2. Use HTML tag and UIWebView.
  3. Use NSMutableAttributedString, this classe is added in iOS from 3.2, it needs Core Text to render rich text on the view. AliSoftware created a useful classe UIAttributedLabel which is an UILabel's subclass and supports NSMutableAttributedString. Check AliSoftware's github for more information.

Aug 19, 2010

(iPhone)How to customize UIAlertView

First solution is using addSubview which add subviews into an UIAlertView, just don't forget add newlines in the initWithTitle method's message to make sure you have enough space for subviews. Like :

[[UIAlertView alloc] initWithTitle:@"Title" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil]

But this solution couldn't change UIAlertView's background, here is second solution that creates an UIAlertView's subclass, overrides several methods (setAlertText, alertText, drawRect, layoutSubviews and show), Joris Kluivers made an excellent sample, check it here : CustomAlert 

(iPhone)How to customize UINavigationBar's background

UINavigationBar has 2 methods to change it's style, barStyle and tintColor, but neither could set a background image for UINavigationBar.

Here is a solution to do that, add following code in your app delegate implementation file (.m) :

@interface UINavigationBar (MyCustomNavBar)
@end
@implementation UINavigationBar (MyCustomNavBar)
- (void) drawRect:(CGRect)rect {
    UIImage *barImage = [UIImage imageNamed:@"background_image.png"];
    [barImage drawInRect:rect];
}
@end

And change the "background_image.png" to the image what you want. This add a category in all UINavationBar used in your application, and you will see a fancy UINavigationBar.

Jul 28, 2010

(iPhone)How to debug EXC_BAD_ACCESS

In iOS programming, the EXC_BAD_ACCESS happens when application try to access some deallocated objects, but the Debugger Console usually display a simple message of "EXC_BAD_ACCESS", here is an useful solution to track the deallocated object.

- Set NSZombieEnabled = YES. With this argument, console will display a little bit more information, like "method : message sent to deallocated instance ...", sometime we can track the object in the method when it is easy to find.

- Set MallocStackLoggingNoCompact = 1, this argument allow to display alloc history of the object, for example: we got a message "message sent to deallocated instance 0x58448e0", type "info malloc-history 0x58448e0" in the console will display the allocate history of object 0x58448e0, which contains object allocation and deallocation, it is really useful to debug the incorrect release call.

To setup these 2 arguments, you should go to "Project"->"Edit Active Executable project name", add these 2 variables in "Variables to be set in the enviroment", names are "NSZombieEnabled" and "MallocStackLoggingNoCompact", values are "YES" and "1". And check the checkbox to active.

Don't forget remove these variables when you release your application.

May 17, 2010

(iPHone)How to retrieve value of "Bundle version"

Here is how to retrieve value of "Bundle version" in the project.plist using code.

NSString *version = [[[NSBundle mainBundle] infoDictionary] 
objectForKey:@"CFBundleVersion"];

(Iphone)How to move up an UIAlertView

Here is a trick to move your UIAlertView up on the screen.

UIAlertView * alert = [ [ UIAlertView alloc ] initWithTitle:@"Alert" 
message:@"Alert" 
delegate:self 
cancelButtonTitle:@"OK" 
otherButtonTitles:nil ];

alert.transform = CGAffineTransformTranslate(alert.transform, 
0.0, 100.0);

[ alert show ];

May 10, 2010

(iPhone)How to resolve "resources have been modified" when install an adhoc version

It's pretty weird my client has met this problem when he install an adhoc version on his iPhone. Arial Balkan posted a very useful solution, the idea is transforming the application (file .app) to an .ipa file which is executable in the iTunes.

May 6, 2010

(XCode)How to resolve Error: 155015 (A conflict in the working copy obstructs the current operation)

It happens on a file i updated from SCM, the solution i found is:

- Backup current working file.
- Run svn revert in console.

Mar 19, 2010

(XCode) How to resolve "Warning: Multiple build commands for output file ..."

Just met a weird warning message in XCode which is "Warning: Multiple build commands for output file ..." after deleting a resource file, and i checked the file does not exist in resource folder any more, finally i found the the file did appear in "targets/app name/copy bundle resources/", than i figure out i accidentally pressed "Delete reference" when i delete the file, and that's why the resource file still exist in the "copy bundle resources" folder