iOS开发之UISwitch控件的使用
2013-08-25 16:10
489 查看
原文地址:http://blog.csdn.net/newjerryj/article/details/6446370
这种switch开关,应该算是apple的又一个界面创新了。 简单直观,使用方便。 本文就来介绍下switch控件在ios中的使用。
在这里,我使用插入图片开关来作为示例吧。
1 从Library中拖一个switch控件在vewcontroller视图控制器上。
2. 在.h 代码中定义变量
UISwitch *switchImage;
并指明属性
@property(nonatomic,retain) IBOutlet UISwitch *switchImage;
动作响应函数
-(IBAction)insertImage:(UISwitch*)sender;
在.m文件中同步下,
@synthesize switchImage;
3. 打开xib, 在view mode中,将File's owner中的响应函数接口和控件的Touch up inside关联起来
4. 编写响应函数
[cpp] view
plaincopy
-(void)insertImage:(UISwitch *)sender{
if (sender==switchImage) {
BOOL isOn=switchImage.on;
if (isOn) {
UIImagePickerController *pickController=[[UIImagePickerController alloc] init];
pickController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
pickController.delegate=self;
[self presentModalViewController:pickController animated:YES];
[pickController release];
}
}
5. 图片管理器的其他响应事件代码
[cpp] view
plaincopy
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
NSString *filePath=[NSTemporaryDirectory() stringByAppendingFormat:@"temp.png"];
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
self.fileUrl=filePath;
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
[switchImage setOn:NO animated:YES];
}
ok, 示例完成。
这种switch开关,应该算是apple的又一个界面创新了。 简单直观,使用方便。 本文就来介绍下switch控件在ios中的使用。
在这里,我使用插入图片开关来作为示例吧。
1 从Library中拖一个switch控件在vewcontroller视图控制器上。
2. 在.h 代码中定义变量
UISwitch *switchImage;
并指明属性
@property(nonatomic,retain) IBOutlet UISwitch *switchImage;
动作响应函数
-(IBAction)insertImage:(UISwitch*)sender;
在.m文件中同步下,
@synthesize switchImage;
3. 打开xib, 在view mode中,将File's owner中的响应函数接口和控件的Touch up inside关联起来
4. 编写响应函数
[cpp] view
plaincopy
-(void)insertImage:(UISwitch *)sender{
if (sender==switchImage) {
BOOL isOn=switchImage.on;
if (isOn) {
UIImagePickerController *pickController=[[UIImagePickerController alloc] init];
pickController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
pickController.delegate=self;
[self presentModalViewController:pickController animated:YES];
[pickController release];
}
}
5. 图片管理器的其他响应事件代码
[cpp] view
plaincopy
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
[picker dismissModalViewControllerAnimated:YES];
UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
NSString *filePath=[NSTemporaryDirectory() stringByAppendingFormat:@"temp.png"];
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
self.fileUrl=filePath;
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissModalViewControllerAnimated:YES];
[switchImage setOn:NO animated:YES];
}
ok, 示例完成。
相关文章推荐
- iOS开发技巧 - 使用和定制开关控件(UISwitch)
- iOS开发-UI控件:UISwitch控件两种使用方法和监听
- iOS开发技巧 - 使用和定制开关控件(UISwitch)
- UISwitch 开关控件—IOS开发
- iOS开发UI基础—25UITableview控件使用小结
- 【IOS 开发】根本 UI 控件详解 (UIButton | UITextField | UITextView | UISwitch)
- IOS开发之纯代码界面----基本控件使用篇2
- iOS 9应用开发教程之使用开关滑块控件以及滚动部署视图
- iOS 5 编程(2)-开关(UISwitch)、分段控件(UISegmentedControl)和Web视图(UIWebView)控件的使用
- iOS开发UI篇—UITableview控件基本使用
- iOS开发UI篇—使用picker View控件完成一个简单的选餐应用
- 【iOS开发-13】大神器:如何利用cocoapods使用第三方类库,以针对UISwitch的第三方类库为例
- IOS开发-常用UI控件的基本使用(Transform形变属性、frame属性、center属性的使用)
- iOS项目开发实战——学会使用TableView列表控件(一)
- IOS开发之纯代码界面----基本控件使用篇4
- iOS开发UI篇—使用picker View控件完成一个简单的选餐应用
- iOS开发之三:常用控件--UILabel的使用
- iOS学习之UISwitch控件两种使用方法和监听
- (温故而知新)iOS开发UI篇—UITableview控件基本使用
- iOS学习之UISwitch控件两种使用方法