Creating an UIImage from a URL

iPhone SDK Tips & Tricks

NSURL *url = [NSURL URLWithString:path];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *img = [[UIImage alloc] initWithData:data];

iPhone Vibrate

iPhone SDK Tips & Tricks


AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);

Don't forget to import AudioServices.h:
#import <AudioToolbox/AudioServices.h>

Text Button Alignment

iPhone SDK Tips & Tricks


UIButton *accountButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
accountButton.frame = CGRectMake(10, 40, 100, 45); // size and position of button
[accountButton setTitle:@"label" forState:UIControlStateNormal];
accountButton.contentVerticalAlignment = UIControlContentVerticalAlignmentBottom;


typedef enum {
UIControlContentVerticalAlignmentCenter = 0,
UIControlContentVerticalAlignmentTop = 1,
UIControlContentVerticalAlignmentBottom = 2,
UIControlContentVerticalAlignmentFill = 3,
} UIControlContentVerticalAlignment;


typedef enum {
UIControlContentHorizontalAlignmentCenter = 0,
UIControlContentHorizontalAlignmentLeft = 1,
UIControlContentHorizontalAlignmentRight = 2,
UIControlContentHorizontalAlignmentFill = 3,
} UIControlContentHorizontalAlignment;