We can change it with the help of UI Kit Framework.
Now lets get started,
- Open Xcode.
- Click on Create a new Xcode project.
- Now select Single View Application.
- Click -> Next.
- Enter -> Product Name and Other blank fields (if any).
- Now select the location where you want to save your project and click on Create.
Write/copy the following code in ViewController.h.
- #
- import < UIKit / UIKit.h >
- @interface ViewController: UIViewController
- {
- UIDatePicker * DatePicker;
- UIPickerView * Picker;
- NSArray * CountryArray;
- NSArray * heightInch;
- NSArray * heightFeet;
- }
- @property(strong, nonatomic) IBOutlet UITextField * dateSelectionTextField;
- @property(strong, nonatomic) IBOutlet UITextField * countryTextField;
- @property(strong, nonatomic) IBOutlet UITextField * heightTextField;
- @end
Copy all in same sequence in ViewController.m
- #
- import "ViewController.h"
- @interface ViewController() < UIPickerViewDataSource, UIPickerViewDelegate >
- @end
- @implementation ViewController
- @synthesize dateSelectionTextField, countryTextField, heightTextField;
- - (void) viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view, typically from a nib.
Now firstly we are going to allocate DatePicker and set input of dateSelectionTextField to DatePicker.
- //For DatePicker
- DatePicker =
- [
- [UIDatePicker alloc] init
- ];
- DatePicker.datePickerMode = UIDatePickerModeDate; //You can change Picker mode here
- [self.dateSelectionTextField setInputView: DatePicker];
Same for Picker but with some custom colour changes.
- //For Picker
- Picker =
- [
- [UIPickerView alloc] init
- ];
- Picker.delegate = self;
- Picker.dataSource = self;
- [Picker setShowsSelectionIndicator: YES];
- Picker.tintColor = [UIColor blackColor];
- Picker.backgroundColor = [UIColor colorWithRed: 153.0 green: 204.0 blue: 255.0 alpha: 2];
These Arrays holds the values of content in Picker.
- //Arrays
- CountryArray =
- [
- [NSArray alloc] initWithObjects: @ "USA", @ "India", @ "France", nil
- ];
- heightFeet =
- [
- [NSArray alloc] initWithObjects: @ "3", @ "4", @ "5", @ "6", @ "7", @ "8", nil
- ];
- heightInch =
- [
- [NSArray alloc] initWithObjects: @ "0", @ "1", @ "2", @ "3", @ "4", @ "5", @ "6", @ "7", @ "8", @ "9", @ "10", @ "11", nil
- ];
This is to set InputView of TextField.
Note: One Picker allocation can be used for multiple text fields.
- //ForPicker
- [self.countryTextField setInputView: Picker];
- [self.heightTextField setInputView: Picker];
Now will make a Toolbar which will provide ease to user to go to another textfields.
- //For ToolBar
- UIToolbar * toolBar =
- [
- [UIToolbar alloc] initWithFrame: CGRectMake(0, 0, 320, 45)
- ];
- [toolBar setTintColor: [UIColor blueColor]];
- UIBarButtonItem * doneBtn =
- [
- [UIBarButtonItem alloc] initWithTitle: @ "Done"
- style: UIBarButtonItemStyleDone target: self action: @selector(Done)
- ];
- UIBarButtonItem * space =
- [
- [UIBarButtonItem alloc] initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target: nil action: nil
- ];
- UIBarButtonItem * prevBtn =
- [
- [UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: @ "765-arrow-left.png"] style: UIBarButtonItemStylePlain target: self action: @selector(previous)
- ];
- UIBarButtonItem * nextBtn = [
- [UIBarButtonItem alloc] initWithImage: [UIImage imageNamed: @ "766-arrow-right.png"] style: UIBarButtonItemStylePlain target: self action: @selector(next)
- ];
- prevBtn.width = 20.0;
- nextBtn.width = 70.0;
- [toolBar setItems: [NSArray arrayWithObjects: prevBtn, nextBtn, space, doneBtn, nil]];
Now this will add the toolbar to textfields.
- //for date textfield
- [self.dateSelectionTextField setInputAccessoryView: toolBar];
- //for country textfield
- [self.countryTextField setInputAccessoryView: toolBar];
- //for Height textfield
- [self.heightTextField setInputAccessoryView: toolBar];
- }


Asfend YarPosted Mar 3, 2016, 3:32 PM
good sardar gee
Banketeshvar NarayanPosted Nov 21, 2015, 11:38 AM
nice share