UIPickerView学习笔记

1. 创建UITabBarController可使用代码及IB两种方式,其中使用代码创建时:

1)在代理的application: didFinishLaunchingWithOptions:中把自定义的UITabBarController对象设为window的rootVieController;

2)需把各分视图放到viewControllers中,这步可在自定义UITabBarController类的viewDidLoad方法中实现,同时预先设置各分时图在tabbar上的图标;

3)设置customizableViewControllers为nil用来禁止用户修改分页


2.Images.xcassets,它被称为资源目录(asset catalog),用来管理应用图标和其他图片。

1)预先准备好图片资源,可不用拷贝到工程中,对于一个名为foo.png的图像,同时应再提供一个foo@2x.png的分辨率加倍的版本;

2)点击Images.xcassets后在有Appicon一栏空白处单击右键--》new image set(新建图标)、new app icon(新建应用程序图标)等

3)新建完毕后重命名,把对应图标的原尺寸版拖到右侧标有[1x]方框中,分辨率加倍的拖到标有[2x]方框中,在程序中可直接使用类似[UIImageimageNamed:@"sevenicon"]来初始化图片对象;

3.date picker

1)在对应控制器的viewDidLoad方法中调用[_datePickersetDate:[NSDatedate] animated:YES];使之显示当前日期、时间;

2)对于日期显示可使用如下语句控制:

NSDateFormatter *dateFormatter = [[NSDateFormatteralloc]init];

dateFormatter.dateFormat =@"yyy-MM-dd HH:mm";//yyy MM dd HH mm均固定用来表示年、月、日、时、分 秒用SS表示

NSString *date=[dateFormatterstringFromDate:_datePicker.date]//_datePicker为UIDatePicker对象


4.UIAlertView

1)创建及显示方法如下:

UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"Date and Time Selected" 

message:message 

delegate:nil //有对应的协议,此处用来指定处理协议的委托对象

cancelButtonTitle:@"That's so true!" 

otherButtonTitles:nil];

[alertshow];//显示提示框


5.UIPickerView

1)协议及数据源分别是UIPickerViewDelegate和UIPickerViewDataSource,凡是使用picke view的控制器都需要满足这两个协议;

2)重要的数据源方法有:

//返回部件个数,滚轮个数

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView

//返回特定pickerView中特定component的行数,本方法会多次调用“刷新”所有滚轮

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component

//返回特定pickerView中特定component的指定row的名称,本方法会多次调用“刷新”所有滚轮

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

//返回特定pickerView中特定component的指定row的视图,本方法会多次调用“刷新”所有滚轮

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

//用户选中某个滚轮的某行时调用

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

//用来动态的选中指定Component的指定Row,动画方式(可选)

selectRow:inComponent:animated:

//获取指定Component中当前被选中的row

selectedRowInComponent

//重新加载滚轮的指定Component(列)

reloadComponent


6.NSBundle 包(bundle)是一种特定类型的文件夹,其中的内容遵循特定的结构,应用程序和框架都是包

1)NSBundle *bundle = [NSBundlemainBundle];//获取当前程序包(路径)

2)NSURL *url = [bundleURLForResource:@"data"withExtension:@"plist"];//获得指定资源的路径

3)_dictionary = [NSDictionarydictionaryWithContentsOfURL:url];//根据指定路径初始化字典

4)_name =_dictionary.allKeys;//获取字典所有的key,数组


7.addTarget:action:forControlEvents: 指定对象使用指定的选择器(方法)去响应指定的事件,如:

[_buttonaddTarget:selfaction:@selector(buttonPressed)forControlEvents:UIControlEventTouchUpInside];


8.performSelector:withObject:afterDelay: 延时特定时间后执行指定的选择器(方法),同时传递参数,如:

[selfperformSelector:@selector(showButton)withObject:nilafterDelay:.5];


9.系统声音创建及播放AudioServicesCreateSystemSoundIDAudioServicesPlaySystemSound

1)使用前需包含<AudioToolbox/AudioToolbox.h> 头文件;

2)系统声音ID类型为SystemSoundID;

3)系统声音的创建、播放代码如下:

//获取声音资源路径

NSURL *soundURL = [[NSBundlemainBundle] URLForResource:@"win"withExtension:@"wav"];

//按照路径创建系统声音,同时修改系统声音ID

AudioServicesCreateSystemSoundID((__bridgeCFURLRef)soundURL, &WinSoundID);

//播放指定系统ID的声音

AudioServicesPlaySystemSound(WinSoundID);


10.UIImageView是用来管理image视图的类,要跟UIImage区分,由UIImage生成UIImageView方法如下:

UIImage *image =[UIImageimageNamed:@"sevenicon"]

UIImageView * imageView = [[UIImageViewalloc]initWithImage:image];


11.获取当前设备的软件版本号

NSLog(@"version = %.1f",[[UIDevicecurrentDevice]systemVersion].floatValue);


12.UIUserNotificationSettings用户提示设置,如下:

     UIUserNotificationSettings *setting = [UIUserNotificationSettingssettingsForTypes:UIUserNotificationTypeSound 

categories:nil];//提示打开声音设置

    

    [[UIApplicationsharedApplication] registerUserNotificationSettings:setting];//注册提示设置

//[UIApplicationsharedApplication]用于获得应用程序的单例




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值