IOS 5新增API介绍及使用
1.UIStepper
[cpp]
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(200, 100, 0, 0)];
[stepper sizeToFit];
stepper.value = 0;
stepper.minimumValue = 0;
stepper.maximumValue = 1;
stepper.stepValue = 0.1;
[stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:stepper];
[stepper release];
UIStepper *stepper = [[UIStepper alloc] initWithFrame:CGRectMake(200, 100, 0, 0)];
[stepper sizeToFit];
stepper.value = 0;
stepper.minimumValue = 0;
stepper.maximumValue = 1;
stepper.stepValue = 0.1;
[stepper addTarget:self action:@selector(stepperAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:stepper];
[stepper release];[cpp] view plaincopyprint?
- (void)stepperAction:(UIStepper *)stepper
{
NSLog(@"stepper value:%f",stepper.value);
}
- (void)stepperAction:(UIStepper *)stepper
{
NSLog(@"stepper value:%f",stepper.value);
}
2.UIAlertView样式
[cpp]
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"Hello World" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
//第一张图 alert.alertViewStyle = UIAlertViewStylePlainTextInput;
//第二张图 alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
//第三张图 alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
[alert show];
[alert release];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello" message:@"Hello World" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
//第一张图 alert.alertViewStyle = UIAlertViewStylePlainTextInput;
//第二张图 alert.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;
//第三张图 alert.alertViewStyle = UIAlertViewStyleSecureTextInput;
[alert show];
[alert release];[cpp] view plaincopyprint?
//返回指定索引值的TextField ,这个API仅存在于IOS5.0以上
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex
{
return textField;
}
//返回指定索引值的TextField ,这个API仅存在于IOS5.0以上
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex
{
return textField;
}3 UIScreen调节亮度
[cpp]
UIScreen *mainScreen = [UIScreen mainScreen];
//设置屏幕亮度为50%
mainScreen.brightness = 0.5;
//默认是NO。如果YES,可以通过wantsSoftwareDimming属性来声明此应用需要将屏幕亮度调整到比中等亮度偏暗的级别。(需要注意的是,打开wantsSoftwareDimming可能会对性能有影响,因为这种昏暗是通过软件来实现的。)
mainScreen.wantsSoftwareDimming = YES;
UIScreen *mainScreen = [UIScreen mainScreen];
//设置屏幕亮度为50%
mainScreen.brightness = 0.5;
//默认是NO。如果YES,可以通过wantsSoftwareDimming属性来声明此应用需要将屏幕亮度调整到比中等亮度偏暗的级别。(需要注意的是,打开wantsSoftwareDimming可能会对性能有影响,因为这种昏暗是通过软件来实现的。)
mainScreen.wantsSoftwareDimming = YES;4 UIReferenceLibraryViewController显示词语解释
[cpp]
NSString *key = @"hello";
//判断任何已经安装的字典里有key的定义
if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:key])
{
UIReferenceLibraryViewController *controller = [[UIReferenceLibraryViewController alloc] initWithTerm:key];
//只是切换方式
[controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:controller animated:YES];
[controller release];
}
NSString *key = @"hello";
//判断任何已经安装的字典里有key的定义
if ([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:key])
{
UIReferenceLibraryViewController *controller = [[UIReferenceLibraryViewController alloc] initWithTerm:key];
//只是切换方式
[controller setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentModalViewController:controller animated:YES];
[controller release];
}5.UISplitViewController delegate,显示隐藏时delegate
UISplitViewController
[cpp]
//这个delegate方法是被发送到你的delegate询问在特定方向下你想要左侧做什么,因此它把自己传递给你,还有左侧,它会问在这个方向你想要我对左侧做什么。要隐藏就返回YES,要保留在屏幕上就返回NO
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInte易做图ceOrientation)orientation
{
return YES;
}
//这个delegate方法是被发送到你的delegate询问在特定方向下你想要左侧做什么,因此它把自己传递给你,还有左侧,它会问在这个方向你想要我对左侧做什么。要隐藏就返回YES,要保留在屏幕上就返回NO
- (BOOL)splitViewController:(UISplitViewController *)svc shouldHideViewController:(UIViewController *)vc inOrientation:(UIInte易做图ceOrientation)orientation
{
return YES;
}6.从xib文件中获取cell
创建UITableViewCell
[cpp]
//为tableview注册一个nib
UINib *nib = [UINib nibWithNibName:@"MyCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"identifier"];
//为tableview注册一个nib
UINib *nib = [UINib nibWithNibName:@"MyCell" bundle:nil];
[self.tableView registerNib:nib forCellReuseIdentifier:@"identifier"];[cpp] view plaincopyprint?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//重用前面注册过的cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];
//other code
return cell;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexP
补充:移动开发 , IOS ,