1.UIPickerView
(1) UIPickerViewDataSource
- 返回pickerView有多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
- 返回第component列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
(2) UIPickerViewDelegate
- 返回第component列第row行的标题
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
- 返回第component列的每一行的行高
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
- 选中第component列第row行的时候调用
注意:这个方法必须用户主动拖动pickerView,才会调用
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
- 返回第component列第row行为一个UIView
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view
2.UIDatePicker
- UIDatePicker有默认的尺寸,可以不用设置frame
- 设置地区
picker.locale = [NSLocale localeWithLocaleIdentifier:@"zh"];
- 设置日期的模式
picker.datePickerMode = UIDatePickerModeDate;
- 监听UIDatePicker的滚动
[picker addTarget:self action:@selector(dateChange:) forControlEvents:UIControlEventValueChanged];
- 日期转换字符串
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"yyyy-MM-dd";
NSString *dateStr = [fmt stringFromDate:datePicker.date];
UITextField
UITextFieldDelegate
- 是否允许开始编辑
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
- 是否允许结束编辑
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
- 是否允许用户输入文字
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
- 文本框开始编辑的时候调用
- (void)textFieldDidBeginEditing:(UITextField *)textField
pch
- 配置pch: buildSetting -> prefix ->
- pch里面的所有内容都是共享,每个文件都会共有:
- 作用:
- 1.存放一些公用的宏
- 2.存放一些公用的头文件
- 3.自定义Log
- 作用:
获取当前的版本号
NSString *version = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
网友评论