- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *backgroundPath = [[NSBundle mainBundle] pathForResource:@"CellBg" ofType:@"png"];
UIImage *backgroundImage = [UIImage imageWithContentsOfFile:backgroundPath];
[cell setBackgroundColor:[UIColor colorWithPatternImage:backgroundImage]];
}
iPhone Helper
Friday, February 25, 2011
Set Image For Header of Section
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(110.0, 25.0, 320, 25.0)];
imgView.image = [UIImage imageNamed:@"Image.png"];
return imgView;
}
{
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(110.0, 25.0, 320, 25.0)];
imgView.image = [UIImage imageNamed:@"Image.png"];
return imgView;
}
Caputure or Pick Image with UIImagePickerController Example
//In header file
#import [UIKit/UIKit.h]
@interface UIPeopleDetailController : UIViewController{
UIImagePickerController *ImagePicker;
NSTimer *timer;
}
-(IBAction)btnCamera_Touch:(id)sender;
@end
//In main file
-(IBAction)btnCamera_Touch:(id)sender
{
ImagePicker = [[UIImagePickerController alloc] init];
ImagePicker.delegate = self;
#if TARGET_IPHONE_SIMULATOR
ImagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#elif TARGET_OS_IPHONE
ImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
//ImagePicker.navigationController.navigationBar.barStyle = UIBarStyleBlack;
ImagePicker.editing = YES;
[self presentModalViewController:ImagePicker animated:YES];
[ImagePicker release];
}
#import [UIKit/UIKit.h]
@interface UIPeopleDetailController : UIViewController
UIImagePickerController *ImagePicker;
NSTimer *timer;
}
-(IBAction)btnCamera_Touch:(id)sender;
@end
//In main file
-(IBAction)btnCamera_Touch:(id)sender
{
ImagePicker = [[UIImagePickerController alloc] init];
ImagePicker.delegate = self;
#if TARGET_IPHONE_SIMULATOR
ImagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
#elif TARGET_OS_IPHONE
ImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
#endif
//ImagePicker.navigationController.navigationBar.barStyle = UIBarStyleBlack;
ImagePicker.editing = YES;
[self presentModalViewController:ImagePicker animated:YES];
[ImagePicker release];
}
UIView Moved Up Example
//In main file you can declare method
BOOL flagTextEdit;
- (void)setViewMovedUp:(BOOL)movedUp{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = self.view.frame;
if (movedUp)
{
rect.origin.y = self.view.frame.origin.y - 185;
}
else
{
rect.origin.y = self.view.frame.origin.y + 185;
}
self.view.frame = rect;
[UIView commitAnimations];
}
#pragma mark -
#pragma mark textField Methods
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if(flagTextEdit)
{
[self setViewMovedUp:NO];
}
flagTextEdit=NO;
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if([textField isEqual:txtEmail] && !flagTextEdit)
{
[self setViewMovedUp:YES];
flagTextEdit=YES;
}
}
BOOL flagTextEdit;
- (void)setViewMovedUp:(BOOL)movedUp{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
CGRect rect = self.view.frame;
if (movedUp)
{
rect.origin.y = self.view.frame.origin.y - 185;
}
else
{
rect.origin.y = self.view.frame.origin.y + 185;
}
self.view.frame = rect;
[UIView commitAnimations];
}
#pragma mark -
#pragma mark textField Methods
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if(flagTextEdit)
{
[self setViewMovedUp:NO];
}
flagTextEdit=NO;
return YES;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
if([textField isEqual:txtEmail] && !flagTextEdit)
{
[self setViewMovedUp:YES];
flagTextEdit=YES;
}
}
Multiple View Navigate Example
//In that case hearder file looks like..
#import [UIKit/UIKit.h]
@interface UIRegisterAccount : UIViewController {
IBOutlet UIView *view2;
IBOutlet UIView *view3;
}
-(IBAction) NextTouch:(id)sender;
-(IBAction) NextTouchUserDetail:(id)sender;
-(IBAction) BackTouchUserDetail:(id)sender;
-(IBAction) BackTouchCreditCard:(id)sender;
-(void)AnimationEnded;
-(void)AnimationEnded2;
@end
//In mail file
-(IBAction) NextTouch:(id)sender
{
[self.view addSubview:view2];
[view2 setFrame:CGRectMake(320, 0, 0, 460)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[view2 setFrame:CGRectMake(0, 0, 320, 460)];
[UIView commitAnimations];
}
-(IBAction) NextTouchUserDetail:(id)sender
{
[self.view addSubview:view3];
[view3 setFrame:CGRectMake(640, 0, 0, 460)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[view3 setFrame:CGRectMake(0, 0, 320, 460)];
[UIView commitAnimations];
}
-(IBAction) BackTouchUserDetail:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[view2 setFrame:CGRectMake(640, 0, 0, 460)];
[UIView setAnimationDidStopSelector:@selector(AnimationEnded)];
[UIView commitAnimations];
}
-(IBAction) BackTouchCreditCard:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[view3 setFrame:CGRectMake(640, 0, 0, 460)];
[UIView setAnimationDidStopSelector:@selector(AnimationEnded2)];
[UIView commitAnimations];
}
-(void)AnimationEnded
{
[view2 removeFromSuperview];
}
-(void)AnimationEnded2
{
[view3 removeFromSuperview];
}
#import [UIKit/UIKit.h]
@interface UIRegisterAccount : UIViewController
IBOutlet UIView *view2;
IBOutlet UIView *view3;
}
-(IBAction) NextTouch:(id)sender;
-(IBAction) NextTouchUserDetail:(id)sender;
-(IBAction) BackTouchUserDetail:(id)sender;
-(IBAction) BackTouchCreditCard:(id)sender;
-(void)AnimationEnded;
-(void)AnimationEnded2;
@end
//In mail file
-(IBAction) NextTouch:(id)sender
{
[self.view addSubview:view2];
[view2 setFrame:CGRectMake(320, 0, 0, 460)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[view2 setFrame:CGRectMake(0, 0, 320, 460)];
[UIView commitAnimations];
}
-(IBAction) NextTouchUserDetail:(id)sender
{
[self.view addSubview:view3];
[view3 setFrame:CGRectMake(640, 0, 0, 460)];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.5];
[view3 setFrame:CGRectMake(0, 0, 320, 460)];
[UIView commitAnimations];
}
-(IBAction) BackTouchUserDetail:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[view2 setFrame:CGRectMake(640, 0, 0, 460)];
[UIView setAnimationDidStopSelector:@selector(AnimationEnded)];
[UIView commitAnimations];
}
-(IBAction) BackTouchCreditCard:(id)sender
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[view3 setFrame:CGRectMake(640, 0, 0, 460)];
[UIView setAnimationDidStopSelector:@selector(AnimationEnded2)];
[UIView commitAnimations];
}
-(void)AnimationEnded
{
[view2 removeFromSuperview];
}
-(void)AnimationEnded2
{
[view3 removeFromSuperview];
}
UIDatePicker Example
//In hearder file
#import [UIKit/UIKit.h]
@interface UISearchOrder : UIViewController {
IBOutlet UILabel *lblOrderDateFrom;
IBOutlet UIView *ViewDatePicker;
IBOutlet UIDatePicker *PickDate;
}
-(IBAction) btnOrderDateFromTouch:(id)sender;
-(IBAction) btnDoneDatePickerTouch:(id)sender;
@end
//In main file
-(IBAction) btnOrderDateFromTouch:(id)sender
{
NSDate *now = [NSDate date];
[PickDate setDate:now];
ViewDatePicker.hidden=NO;
}
-(IBAction) btnDoneDatePickerTouch:(id)sender
{
NSDate *selected = [PickDate date];
lblOrderDateFrom.text=[NSString stringWithFormat:@"%@" ,selected];
ViewDatePicker.hidden=YES;
}
#import [UIKit/UIKit.h]
@interface UISearchOrder : UIViewController
IBOutlet UILabel *lblOrderDateFrom;
IBOutlet UIView *ViewDatePicker;
IBOutlet UIDatePicker *PickDate;
}
-(IBAction) btnOrderDateFromTouch:(id)sender;
-(IBAction) btnDoneDatePickerTouch:(id)sender;
@end
//In main file
-(IBAction) btnOrderDateFromTouch:(id)sender
{
NSDate *now = [NSDate date];
[PickDate setDate:now];
ViewDatePicker.hidden=NO;
}
-(IBAction) btnDoneDatePickerTouch:(id)sender
{
NSDate *selected = [PickDate date];
lblOrderDateFrom.text=[NSString stringWithFormat:@"%@" ,selected];
ViewDatePicker.hidden=YES;
}
UIPickerView Example
//In header file
#import [UIKit/UIKit.h]
@interface UISearchOrder : UIViewController {
IBOutlet UILabel *lblOrderDateFrom;
IBOutlet UILabel *lblOrderDateTo;
IBOutlet UILabel *lblOrderCompDateFrom;
IBOutlet UILabel *lblOrderCompDateTo;
IBOutlet UIView *viewPicker;
IBOutlet UIPickerView *pickData;
}
-(IBAction) btnPaymentTouch:(id)sender;
-(IBAction) btnDonePickerTouch:(id)sender;
@end
//In main file
#import "UISearchOrder.h"
@implementation UISearchOrder
NSArray *picker_global, *arr_Payment;
- (void)viewDidLoad {
[super viewDidLoad];
arr_Payment = [[NSArray alloc] initWithObjects:@"All",@"Paid",@"Pending",nil];
}
-(IBAction) btnPaymentTouch:(id)sender
{
picker_global=arr_Payment;
[pickData reloadComponent:0];
viewPicker.hidden=NO;
}
-(IBAction) btnDonePickerTouch:(id)sender
{
lblPayment.text= [arr_Payment objectAtIndex:[pickData selectedRowInComponent:0]];
viewPicker.hidden = YES;
}
#pragma mark -
#pragma mark Picker View Methods
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [picker_global objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
}
#pragma mark -
#pragma mark UIPickerViewDataSource methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [picker_global count];
}
#import [UIKit/UIKit.h]
@interface UISearchOrder : UIViewController
IBOutlet UILabel *lblOrderDateFrom;
IBOutlet UILabel *lblOrderDateTo;
IBOutlet UILabel *lblOrderCompDateFrom;
IBOutlet UILabel *lblOrderCompDateTo;
IBOutlet UIView *viewPicker;
IBOutlet UIPickerView *pickData;
}
-(IBAction) btnPaymentTouch:(id)sender;
-(IBAction) btnDonePickerTouch:(id)sender;
@end
//In main file
#import "UISearchOrder.h"
@implementation UISearchOrder
NSArray *picker_global, *arr_Payment;
- (void)viewDidLoad {
[super viewDidLoad];
arr_Payment = [[NSArray alloc] initWithObjects:@"All",@"Paid",@"Pending",nil];
}
-(IBAction) btnPaymentTouch:(id)sender
{
picker_global=arr_Payment;
[pickData reloadComponent:0];
viewPicker.hidden=NO;
}
-(IBAction) btnDonePickerTouch:(id)sender
{
lblPayment.text= [arr_Payment objectAtIndex:[pickData selectedRowInComponent:0]];
viewPicker.hidden = YES;
}
#pragma mark -
#pragma mark Picker View Methods
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [picker_global objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
}
#pragma mark -
#pragma mark UIPickerViewDataSource methods
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return [picker_global count];
}
Subscribe to:
Posts (Atom)