iOS学习项目(14-UIPicker&UIDatePicker)

来源:互联网 发布:淘宝和田玉店铺 编辑:程序博客网 时间:2024/06/08 18:36

UIPicker

①UIPicker与UITableView有些相似
1、
UITableView需要返回section和row个数(组与元素)
UIPicker需要返回component和row(列与行)

// returns the number of 'columns' to display.- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;// returns the # of rows in each component..- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;

2、
UITableView里面可以重用cell,UIPicker里也可以重用view

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view;

其中reusingView就是重用view。【备注:此方法可用于自定义view】
当然,UIPicker也可以直接返回NSString作为元素。

- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

3、
UIPicker也有选中的方法和刷新方式
选中方式

// selection. in this case, it means showing the appropriate row in the middle- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;

刷新方式

// Reloading whole view or single component- (void)reloadAllComponents;- (void)reloadComponent:(NSInteger)component;

②arc4random-uniform(u_int32_t)
可以产生0~(指定数字-1) 的随机整数。
若想产生0.1~0.9之间的数,只需arc4random-uniform(10) * 0.1即可


UIDatePicker

①UIDatePicker里两个比较重要属性
1、locale区域

/** 用代码自己创建的话,用如下方法。其中"zh"代表中国。* 当然你也可以用[NSLocale availableLocaleIdentifiers]查询有哪些可以选择的区域*/[[NSLocale alloc]initWithLocaleIdentifier:@"zh"];

2、datePickerMode显示时间的模式

②textField的inputView可以用用于自定义各种键盘弹出视图
inputAccessoryView用于设置键盘上的辅助视图

③UIToolbar内部的空间是UIBarButtonItem(当然你要放其他view也行,因为其本质也为UIView)
其中UIBarButtonItem分两种,一种用于显示的,一种为占位的。
占位的有两种:fixed与flexible(固定于可变)

④日期格式:yyyyMMddHHmmss

0 0
原创粉丝点击