Friday 27 July 2012

Drop Down Custom View For iPhone applications.


Wanted to have a drop-down view like we have in html element, allows user to select one option form list of option.
Have created sample application that demonstrates the use of this custom view.
Sample project available to download athttp://code.google.com/p/dropdowndemo/downloads/list.
Adding instruction how to use view in you application.
  1. Import QuartzCore.framework in your application.
  2. Import DropDownView.h file in the view controller.
  3. Have an class variable dataArray to store data to be put into the table and make a class variable of DropDownView. Making DropDownView variable allows you to control the DropDownView.
  4. Use the DropDownViewDelgate and declare the delegate method in your application.
  5. Initialize the DropdownView variable and add the view in your current view, andy your ready to go.
Below a demo sample classes.

FirstController.h

--------------------
#import <UIKit/UIKit.h>

#import "DropDownView.h"

@interface FirstController : UIViewController<DropDownViewDelegate> {

 UIButton *button;

 NSArray *arrayData;

 DropDownView *dropDownView;

}

@property (nonatomic,retain) IBOutlet UIButton *button;

-(IBAction)actionButtonClick;

@end

--------------

FirstController.m

-----------
#import "FirstController.h"

@implementation FirstController

@synthesize button;

- (void)viewDidLoad {

 [super viewDidLoad];

 arrayData = [[NSArray alloc] initWithArray:[NSArray arrayWithObjects:@"Test1",@"Test2",nil]];

 dropDownView = [[DropDownView alloc] initWithArrayData:arrayData cellHeight:30 heightTableView:200 paddingTop:-8 paddingLeft:-5 paddingRight:-10 refView:button animation:BLENDIN openAnimationDuration:2 closeAnimationDuration:2];

 dropDownView.delegate = self;

 [self.view addSubview:dropDownView.view];

 [button setTitle:[arrayData objectAtIndex:0] forState:UIControlStateNormal];

}

- (void)didReceiveMemoryWarning {
 [super didReceiveMemoryWarning];
}

- (void)viewDidUnload {
 [super viewDidUnload];

}

- (void)dealloc {

 [button release];

 [super dealloc];

}

#pragma mark -
#pragma mark DropDownViewDelegate

-(void)dropDownCellSelected:(NSInteger)returnIndex{

 [button setTitle:[arrayData objectAtIndex:returnIndex] forState:UIControlStateNormal];

}    

#pragma mark -
#pragma mark Class methods

-(IBAction)actionButtonClick{

 [dropDownView openAnimation];

}    

@end

------------


DropDownView Class File are available in above linked ProjectDemo.

 

No comments:

Post a Comment