Customize UISlider color

This post will explain you how to do this :

Instead of having 3 UISlider with 3 UILabels telling red, green, blue, we have 3 UISlider with custom colors. Everybody would agree that this is nicer…

To do this, just customize your UISlider this way :

[redSlider setMinimumTrackImage:[[UIImage imageNamed:@"redSlider.png"] stretchableImageWithLeftCapWidth:10.0 topCapHeight:0.0] forState:UIControlStateNormal];

Then you just need the images. Taken (and edited) from the UICatalog Apple Template :

ABPeoplePickerNavigationController + delegate

Just because I made the mistake and lost a lot of time on this one. The property to set the ABPeoplePickerNavigationController delegate is not “delegate” but “peoplePickerDelegate”. Otherwise, you never get called and no error is displayed so you loose a lot of time trying to find the problem.

ABPeoplePickerNavigationController* controller = [[ABPeoplePickerNavigationController alloc] init];

controller.peoplePickerDelegate = self;

[self presentModalViewController:controller animated:YES];

Deselecting a row in an UITableView…

When a user click on a row in a UITableView, it goes in selected style. You need to deselect the row when he click on it so you implements :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

//Do something interesting here

//Do not do this because the row will be deselected at first but once the table view will “reload” the row, it will appear selected

//tableView.selected = NO;

//Do this instead :

[tableView deselectRowAtIndexPath:indexPath animated:YES];

}

inApp AppStore Links

To open the AppStore from an App, I use :

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/us/app/touch-player/id330269823?mt=8&uo=6"]];

You can get the link to your App with the “iTunes Link Maker” (just Google it).

Cocos2D – Menu

Cocos2D for iPhone is great for 2D game developpement on the iPhone. And what’s the first thing a user will see when he starts your game? That’s right, a menu!

Create a menu with cocos2D is really simple. You first create a Scene and a Layer for your menu (with a nice background image if possible). Then you can create your menu items (MenuItem class) :

MenuItem *startGame = [MenuItemFont itemFromString:@"Start Game" target:self selector:@selector(startGame)];

MenuItem *help  = [MenuItemFont itemFromString:@"Help" target:self selector:@selector(help)];

MenuItem *about  = [MenuItemFont itemFromString:@"About" target:self selector:@selector(about)];

When you menu items are created, you just need to add them in your menu (Menu class) and customize the layout :

Menu *menu = [Menu menuWithItems: startGame, help, about, nil];

[menu alignItemsVertically];

Finally, you add your menu to your layer :

[self addChild:menu];

That’s it your menu has been created. This code snippets don’t give the implementation of the methods triggered when pressing the buttons (target: selector: ) but here is what you will probably do :

-(void)startGame{

[[Director sharedDirector] replaceScene:[GameScene node]];

}

But you can do whatever you want e.g. create a transition or a UIKit view. But that’s another story…

Follow

Get every new post delivered to your Inbox.