IOS通用应用程序 简介 通用的应用程序是为iPhone和iPad在一个单一的二进制文件中设计的应用程序。这有助于代码重用,并能够帮助更快进行更新。 实例步骤 1、创建一个简单的View based application(视图应用程序) 2、在文件查看器的右边,将文件ViewController.xib的文件名称更改为ViewController_iPhone.xib,如下所示 3、选择”File -> New -> File… “,然后选择User Interface,再选择View,单击下一步 4、选择iPad作为设备,单击下一步: 5、将该文件另存为ViewController_iPad.xib,然后选择创建 6、在ViewController_iPhone.xib和ViewController_iPad.xibd的屏幕中心添加标签 7、在ViewController_iPhone.xib中选择identity inspector,设置custom class为ViewController 8、更新AppDelegate.m中的 application:DidFinishLaunching:withOptions方法 – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. if…
Category: Mobile
IOS相机管理 相机简介 相机是移动设备的共同特点之一,我们能够使用相机拍摄图片,并在应用程序里调用它,而且相机的使用很简单。 实例步骤 1、创建一个简单的View based application 2、在ViewController.xib中添加一个button (按钮),并为该按钮创建IBAction 3、添加一个 image view (图像视图),并创建一个名为imageView的IBOutlet 4、ViewController.h文件代码如下所示: #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIImagePickerControllerDelegate> { UIImagePickerController *imagePicker; IBOutlet UIImageView *imageView; } – (IBAction)showCamera:(id)sender; @end 5、修改ViewController.m,如下所示: #import “ViewController.h” @interface ViewController () @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; }…
IOS警告对话框的使用 警告对话框用来给用户提供重要信息。 仅在警告对话框视图中选择选项后,才能着手进一步使用应用程序。 重要的属性 alertViewStyle cancelButtonIndex delegate message numberOfButtons title 重要的方法 – (NSInteger)addButtonWithTitle:(NSString *)title – (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex – (void)dismissWithClickedButtonIndex: (NSInteger)buttonIndex animated:(BOOL)animated – (id)initWithTitle:(NSString *)title message: (NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString*)otherButtonTitles, … – (void)show 更新 ViewController.h,如下所示 让类符合警告对话框视图的委托协议,如下所示,在ViewController.h中添加<UIAlertViewDelegate> #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIAlertViewDelegate>{ } @end…
IOS图标的使用 IOS图标是用于应用程序相关的操作。 IOS 中的不同图标 AppIcon App Store 的应用程序图标 搜索结果和设置的小图标 工具栏和导航栏图标 选项卡栏图标 AppIcon AppIcon 是出现在设备SpringBoard (默认屏幕上的所有的应用程序) 的应用程序的图标。 App Store 的应用程序图标 它是512 x 512 或 1024 x 1024(推荐大小)的高分辨率的应用程序图标。 搜索结果和设置的小图标 在搜索列表的应用程序中使用这个小图标。 它还用于与相关的应用程序的功能是启用和禁用的设置屏幕上。如:启用定位服务。 工具栏和导航栏图标 工具栏和导航栏中使用特制的标准图标的列表。它包括的份额,像图标相机,撰写等等。 选项卡栏图标 选项卡栏中使用一系列特制的标准图标列表。它包括的图标有书签、 联系人、 下载等。 有的不同的 iOS 设备的每个图标大小的都不一样。你可以查看更多关于苹果文件中图标的准则:ios人机交互界面指南。
选择器的使用 选择器是一个可滚动视图,用于选取列表项中的值。 重要的属性 delegate dataSource 重要的方法 – (void)reloadAllComponents – (void)reloadComponent:(NSInteger)component – (NSInteger)selectedRowInComponent:(NSInteger)component – (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated 修改 ViewController.h 我们将添加一个文本字段、选择器视图和一个数组。 我们将采用UITextFieldDelegate、UIPickerViewDataSource、UIPickerViewDelegate的协议。ViewController.h文件代码如下所示: #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UITextFieldDelegate,UIPickerViewDataSource,UIPickerViewDelegate> { UITextField *myTextField; UIPickerView *myPickerView; NSArray *pickerArray; } @end 添加自定义方法 addPickerView -(void)addPickerView{ pickerArray = [[NSArray alloc]initWithObjects:@”Chess”, @”Cricket”,@”Football”,@”Tennis”,@”Volleyball”,…
IOS开关的使用 开关用于打开和关闭状态之间的切换。 重要的属性 onImage offImage on 重要的方法 – (void)setOn:(BOOL)on animated:(BOOL)animated 添加自定义方法 addSwitch 和开关 -(IBAction)switched:(id)sender{ NSLog(@”Switch current state %@”, mySwitch.on ? @”On” : @”Off”); } -(void)addSwitch{ mySwitch = [[UISwitch alloc] init]; [self.view addSubview:mySwitch]; mySwitch.center = CGPointMake(150, 200); [mySwitch addTarget:self action:@selector(switched:) forControlEvents:UIControlEventValueChanged]; } 在 ViewController.m 中修改 viewDidLoad,如下所示…
IOS滑块的使用 滑块用于从某个范围的值里选择的一个值。 重要的属性 continuous maximumValue minimumValue value 重要的方法 – (void)setValue:(float)value animated:(BOOL)animated 添加自定义方法 addSlider 和 sliderChanged -(IBAction)sliderChanged:(id)sender{ NSLog(@”SliderValue %f”,mySlider.value); } -(void)addSlider{ mySlider = [[UISlider alloc] initWithFrame:CGRectMake(50, 200, 200, 23)]; [self.view addSubview:mySlider]; mySlider.minimumValue = 10.0; mySlider.maximumValue = 99.0; mySlider.continuous = NO; [mySlider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged]; } 在…
IOS文本视图的使用 文本视图用于显示多行滚动的文本。 重要属性 dataDetectorTypes delegate editable inputAccessoryView inputView text textAlignment textColor 重要的委托方法 -(void)textViewDidBeginEditing:(UITextView *)textView -(void)textViewDidEndEditing:(UITextView *)textView -(void)textViewDidChange:(UITextView *)textView -(BOOL)textViewShouldEndEditing:(UITextView *)textView 添加自定义方法 addTextView -(void)addTextView{ myTextView = [[UITextView alloc]initWithFrame: CGRectMake(10, 50, 300, 200)]; [myTextView setText:@”Lorem ipsum dolor sit er elit lamet, consectetaur cillium adipisicing pecu, sed do…
IOS视图切换的使用 视图切换通过一系列动画效果实现,包括折叠切换、爆炸切换、卡片式切换等等。 修改 ViewController.xib,如下所示 在 xib 中创建按钮的操作 修改 ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController { UIView *view1; UIView *view2; } -(IBAction)flipFromLeft:(id)sender; -(IBAction)flipFromRight:(id)sender; -(IBAction)flipFromTop:(id)sender; -(IBAction)flipFromBottom:(id)sender; -(IBAction)curlUp:(id)sender; -(IBAction)curlDown:(id)sender; -(IBAction)dissolve:(id)sender; -(IBAction)noTransition:(id)sender; @end 在 ViewController 类中声明两个视图的实例。ViewController.h文件代码如下: 修改 ViewController.m 我们将添加自定义方法setUpView来初始化视图。 我们还将创建了另一种方法doTransitionWithType: 实现view1切换到view2,反之亦然。 后我们将执行之前创建的操作的方法即调用 doTransitionWithType: 方法与切换类型。ViewController.m代码如下: #import “ViewController.h” @interface ViewController…
滚动视图的使用 如果内容超出屏幕的大小就会使用到滚动视图来显示隐藏的部分。 它可以包含所有的其他用户界面元素 如图像视图、 标签、 文本视图甚至另一个滚动视图。 重要的属性 contentSize contentInset contentOffset delegate 重要的方法 – (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated – (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated 重要的委托方法 在ViewController.h中,加入滚动视图和声明滚动视图让类符合委托协议,如下所示: #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIScrollViewDelegate> { UIScrollView *myScrollView; } @end 添加自定义方法 addScrollView -(void)addScrollView{ myScrollView = [[UIScrollView alloc]initWithFrame: CGRectMake(20, 20, 280, 420)]; myScrollView.accessibilityActivationPoint = CGPointMake(100,…


