Skip to main content

Posts

Showing posts from July, 2012

UINavigationBar: How to customize Navigation Bar

By customization we can change look and feel of Navigation Bar. Below is sample code which demonstrates how to customize Navigation Bar. We can achieve this by using Categories in Objective-C: Code Sample: /*********************************************************/ @interface UINavigationBar (CustomNavBarImage)  - (void) setNavBackgroundImage:(UIImage*)bgImage;  - (void) removeNavBackgroundImage ; @end /************************************************************/ //.m file (Implementaion file) #import "UINavigationBar+CustomNavBarImage.h" @implementation UINavigationBar (CustomNavBarImage) - (void) setNavBackgroundImage:(UIImage*)bgImage {  if (bgImage == NULL)  return; UIImageView *myImageView= [[UIImageView alloc] initWithImage:bgImage]; myImageView.frame = CGRectMake(0,0,320,44); [self addSubview:myImageView]; [myImageView release]; // If You want to add some buttons and title go through that //[myImageView release]; UI...

UIButton : How to create a UIButton Programmatically

Sample Code: // Set a method for this -(void) addButtonWithFrame :(CGRect ) btnFrame  andName: (NSString *) titleName { UIButton *addButton = [UIButton buttonWithType: UIButtonTypeCustom]; // (Value = 0) means NO Button Style. /* iOS Library provide more Types of UIButton , like UIButtonTypeRoundedRect (Value = 1), Means a Rounded-Rectangle Style UIButtonTypeDetailDisclosure (Value = 2), Means a Details Disclosure Button UIButtonTypeInfoLight (Value = 3), Means an Information button with light background UIButtonTypeInfoDark (Value = 4), Means an Information Button with dark background UIButtonTypeContactAdd (Value = 5), Means a contact add button. You can choose any one of them. */ //Set Button Frame addButton.frame = btnFrame; //Set Tag addButton.tag = cnt; //cnt = 0,1,2…..so on. // Set Title [addButton setTitle : titleName forState: UIControlSateNormal]; //If you want to user touch and title highlighted, changes the state like : // [add...

UIImageView: Show Images from URL,Resources Folder, and Document Directory

Use the following functions to get Image from Web URL or Main Bundle (Resource Folder) or Document Directory // From URL -(UIImage *) getImageFromURL : (NSString *) urlString { NSURL *pathURL = [NSURL URLWithString: urlString]; NSData *imageData = [NSData dataWithContentOfURL:pathURL]; UIImage *getImage = [[UIImage alloc]initWithData:imageData]; return getImage; } // From Bundle -(UIImage *) getImageFromResources_FileName: (NSString *)file_Name andFileType: (NSString *) file_Extension { NSString *filePath = [[NSBundle mainBundle] pathForResource : file_Name ofType: file_Extension]; UIImage *getImage = [UIImage imageWithContentsOfFile:filePath]; return getImage; } // From Document Directory (NSDocumentDirectory) -(UIImage *) getImageFromDocumentDirectory_ImageName:(NSString *) imageName { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *docDirectory = [paths objectAtIndex:0]; NSString *...