Skip to main content

Posts

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 *...

Freshers: Programming Questions (Set - 1)

Hello Friends,                      Here the some basic question lists in C and C++ programming language , which are most frequently asked questions in an freshers level / experienced interview in software companies in India. Write a program to Swap two numbers : using third variable without third variable using bit-wise operator   Write a program for  Pass By Value Pass By Reference Recursion Program: Prime Number Factorial series Fibonacci Series Sum  of Series Palindrome A partition of a positive integer n is a sequence of positive integers that sum to n. Write a program to print all non-increasing partitions of n. eg.   n=4       4       3 1       2 2       2 1 1       1 1 1 1 Print this p...

Use NSUserDefault

If you have an application that should save any values or objects or preferences (like : how to access preference from your iOS Applications )  for example state of a switch, state of background and you don’t want use database for that small request you can simply add instance of NSUserDefaults class in your implementation. Information About NSUserDefaults: With the NSUserDefaults class, you can save settings and properties related to application or user data. For example, you could save a profile image set by the user or a default color scheme for the application. The objects will be saved in what is known as the iOS “defaults system”. The iOS defaults system is available throughout all of the code in your app, and any data saved to the defaults system will persist through application sessions . This means that even if the user closes your application or reboots their phone, the saved data will still be available the next time they open the app! Main Points: ...

Creating Timestamp

In Objective C and iOS , Some times you need to create a time stamp(Unix Time Stamp Style) you use like this : NSString * timeStampValue = [NSString stringWithFormat:@"%d", (long)[[NSDate date] timeIntervalSince1970]]; NSLog(@"Time Stamp Value == %@", timeStampValue); /* Explain: This translates to current server time of 04/13/2012 @ 8:41am in EST. TIME STAMP: 1334320615 DATE (M/D/Y @ h:m:s): 04 / 13 / 12 @ 7:36:55am EST */ ======================== Output : 1334320615 ========================