image compression by size – iPhone SDK

Heres some example code that will attempt to compress an image for you so that it doesn’t exceed either a max compression or maximum file size CGFloat compression = 0.9f; CGFloat maxCompression = 0.1f; int maxFileSize = 250*1024; NSData *imageData = UIImageJPEGRepresentation(yourImage, compression); while ([imageData length] > maxFileSize && compression > maxCompression) { compression -= … Read more

Make Background of UIView a Gradient Without Sub Classing

You can use +[UIColor colorWithPatternImage:] to produce a patterned background. Example (bring your own CGGradient): // Allocate color space CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); // Allocate bitmap context CGContextRef bitmapContext = CGBitmapContextCreate(NULL, 320, 480, 8, 4 * 320, colorSpace, kCGImageAlphaNoneSkipFirst); //allocate myGradient CGFloat locationList[] = {0.0f, 1.0f}; CGFloat colorList[] = {0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, … Read more

iOS multitasking for an Audio Recording application

You can. Skype does this. You presumably need to set <key>UIBackgroundModes</key><array><string>audio</string></array> in Info.plist, and you need to make sure that the audio session is active/running/whatever before you switch apps (the assumption is that you won’t suddenly start recording/playing music/whatever when your app is in the background). The docs say that “audio” lets you play audio … Read more

How to know if a UITextField in iOS has blank spaces

You can “trim” the text, that is remove all the whitespace at the start and end. If all that’s left is an empty string, then only whitespace (or nothing) was entered. NSString *rawString = [textField text]; NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet]; NSString *trimmed = [rawString stringByTrimmingCharactersInSet:whitespace]; if ([trimmed length] == 0) { // Text was … Read more

How to know if a UITextField in iOS has blank spaces

You can “trim” the text, that is remove all the whitespace at the start and end. If all that’s left is an empty string, then only whitespace (or nothing) was entered. NSString *rawString = [textField text]; NSCharacterSet *whitespace = [NSCharacterSet whitespaceAndNewlineCharacterSet]; NSString *trimmed = [rawString stringByTrimmingCharactersInSet:whitespace]; if ([trimmed length] == 0) { // Text was … Read more

iPhone : How to set BackgroundColor of UIButton with buttonType UIButtonTypeCustom

You could create an image programmatically and so have the ability to use your colors in a dynamic way: Create a category for UIButton with this method and be sure to have QuartzCore lib imported via @import QuartzCore: – (void)setColor:(UIColor *)color forState:(UIControlState)state { UIView *colorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)]; colorView.backgroundColor = color; … Read more