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…
Tag: iOS
IOS加速度传感器(accelerometer) 简介 加速度传感器是根据x、y和z三个方向来检测在设备位置的改变。 通过加速度传感器可以知道当前设备相对于地面的位置。 以下实例代码需要在真实设备上运行,在模拟器上是无法工作的。 实例步骤 1、创建一个简单的视图应用程序 2、在ViewController.xib中添加三个标签,并创建一个ibOutlets分别为:xlable、ylabel和zlabel 3、如下所示,更新ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController<UIAccelerometerDelegate> { IBOutlet UILabel *xlabel; IBOutlet UILabel *ylabel; IBOutlet UILabel *zlabel; } @end 4、如下所示,更新ViewController.m #import “ViewController.h” @interface ViewController () @end @implementation ViewController – (void)viewDidLoad { [super viewDidLoad]; [[UIAccelerometer sharedAccelerometer]setDelegate:self]; //Do any…
IOS图标的使用 IOS图标是用于应用程序相关的操作。 IOS 中的不同图标 AppIcon App Store 的应用程序图标 搜索结果和设置的小图标 工具栏和导航栏图标 选项卡栏图标 AppIcon AppIcon 是出现在设备SpringBoard (默认屏幕上的所有的应用程序) 的应用程序的图标。 App Store 的应用程序图标 它是512 x 512 或 1024 x 1024(推荐大小)的高分辨率的应用程序图标。 搜索结果和设置的小图标 在搜索列表的应用程序中使用这个小图标。 它还用于与相关的应用程序的功能是启用和禁用的设置屏幕上。如:启用定位服务。 工具栏和导航栏图标 工具栏和导航栏中使用特制的标准图标的列表。它包括的份额,像图标相机,撰写等等。 选项卡栏图标 选项卡栏中使用一系列特制的标准图标列表。它包括的图标有书签、 联系人、 下载等。 有的不同的 iOS 设备的每个图标大小的都不一样。你可以查看更多关于苹果文件中图标的准则:ios人机交互界面指南。
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滑块的使用 滑块用于从某个范围的值里选择的一个值。 重要的属性 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开关的使用 开关用于打开和关闭状态之间的切换。 重要的属性 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,如下所示…
选择器的使用 选择器是一个可滚动视图,用于选取列表项中的值。 重要的属性 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视图切换的使用 视图切换通过一系列动画效果实现,包括折叠切换、爆炸切换、卡片式切换等等。 修改 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…
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…
分割视图的使用 分割视图是 iPad 的特定视图控制器用于管理两个视图控制器,在左侧是一个主控制器,其右侧是一个详细信息视图控制器。 重要的属性 delegate viewControllers 示例代码和步骤 1.创建一个新项目,选择Master Detail Application并单击下一步,输入项目名称,然后选择创建。 2.简单的分割视图控制器与母版中的表视图是默认创建的。 3.在这里我们为我们创建的下列文件。 AppDelegate.h AppDelegate.m DetailViewController.h DetailViewController.m DetailViewController.xib MasterViewController.h MasterViewController.m MasterViewController.xib 4. AppDelegate.h文件如下所示 #import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) UISplitViewController *splitViewController; @end 5.在AppDelegate.m中的didFinishLaunchingWithOptions方法,如下所示 – (BOOL)application:(UIApplication *)application…


