Tag Archives: cocoa framework

(Objective C) Enable UIButton inside UIImageView

When you add a UIButton as a subview to UIImageView, it will not correspond to touch events automatically, UIImageView’s userinteraction property needs to be set

Posted in Objective-C | Also tagged , , , , , , | Leave a comment

Scaling an image in Objective-C (Cocoa Framework)

The UIImage class can be used to represent an image. The following snippet scales an image according to a size which is provided with a CGSize parameter. + (UIImage *)scale:(UIImage *)image toSize:(CGSize)size { UIGraphicsBeginImageContext(size); [image drawInRect:CGRectMake(0, 0, size.width, size.height)]; UIImage *scaledImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return scaledImage; }

Posted in Objective-C | Also tagged , , , , , , , , , , | Leave a comment

Run a method in a separate thread in Objective-C (Cocoa Framework)

In some situations, performing operations in a single thread can cause an application to appear as if it is hanging. For example, when searching with autocomplete enabled within a large amount of records in a database . The user is typing and the application is performing a computationally complex operation at the same time (searching [...]

Posted in Objective-C | Also tagged , , , , , , , , , , | 1 Comment

Show/Hide iPhone Status Bar

Show/Hide iPhone Status Bar //Hide [UIApplication sharedApplication].statusBarHidden = YES; //Show [UIApplication sharedApplication].statusBarHidden = NO; http://codesnippets.joyent.com/posts/show/12742

Posted in Objective-C | Also tagged , , , , , , , | Leave a comment

Toggle iPhone network indicator in status bar

Toggle iPhone network indicator in status bar //show [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; //hide [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; http://codesnippets.joyent.com/posts/show/12742

Posted in Objective-C | Also tagged , , , , , , , , | Leave a comment

Simple alert box on iPhone

Simple alert box on iPhone UIAlertView *someError = [[UIAlertView alloc] initWithTitle: @”Network error” message: @”Error sending your info to the server” delegate: self cancelButtonTitle: @”Ok” otherButtonTitles: nil]; [someError show]; [someError release]; http://codesnippets.joyent.com/posts/show/12744

Posted in Objective-C | Also tagged , , , , , , , , | Leave a comment

Animate A Fade-Out Of A NSWindow With Objective-C

Animate A Fade-Out Of A NSWindow With Objective-C – (void)fadeOutWindow:(NSWindow*)window{ float alpha = 1.0; [window setAlphaValue:alpha]; [window makeKeyAndOrderFront:self]; for (int x = 0; x < 10; x++) { alpha -= 0.1; [window setAlphaValue:alpha]; [NSThread sleepForTimeInterval:0.020]; } } http://codesnippets.joyent.com/posts/show/12745

Posted in Objective-C | Also tagged , , , , , , , | Leave a comment

(Objective-C) Basic NSTableView Control Functions (Cocoa Framework)

Basic NSTableView Control Functions

Posted in Objective-C | Also tagged , , , , , , , | Leave a comment

(Objective C) Play a sound file

// Play sound //To load sound file. +(void) playSound:(NSString *)fileName { NSString *path = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath],fileName];</code> <code>//declare a system sound id SystemSoundID soundID; //Get a URL for the sound file NSURL *filePath = [NSURL fileURLWithPath:path isDirectory:NO]; //Use audio sevices to create the sound AudioServicesCreateSystemSoundID((CFURLRef)filePath, &soundID); </code> <code> //Use audio services to play the [...]

Posted in Objective-C | Also tagged , , , , , , , | Leave a comment

UIWebView to display web content (Cocoa Framework)

UIWebViews can be used to display web pages (for example, within iPhone applications). The snippets below demonstrate a view controller to display http://snipd.net .

Posted in Objective-C | Also tagged , , , , , , , , | Leave a comment