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…
Tag: Mobile
选择器的使用 选择器是一个可滚动视图,用于选取列表项中的值。 重要的属性 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视图切换的使用 视图切换通过一系列动画效果实现,包括折叠切换、爆炸切换、卡片式切换等等。 修改 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…
表格视图的使用 IOS表格视图由单元格 (一般可重复使用) 组成,用于显示垂直滚动的视图。 在iOS 中,表格视图用于显示数据列表,如联系人、待办事项或购物项列表。 重要的属性 delegate dataSource rowHeight sectionFooterHeight sectionHeaderHeight separatorColor tableHeaderView tableFooterView 重要的方法 – (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath – (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation – (id)dequeueReusableCellWithIdentifier:(NSString *)identifier – (id)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath – (void)reloadData – (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation – (NSArray *)visibleCells 示例代码和步骤 1.在ViewController.xib中添加表格视图,如下所示 2. 通过右键单击并选择数据源和委托将委托和数据源设定到”File’s…
滚动视图的使用 如果内容超出屏幕的大小就会使用到滚动视图来显示隐藏的部分。 它可以包含所有的其他用户界面元素 如图像视图、 标签、 文本视图甚至另一个滚动视图。 重要的属性 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,…
图像视图的使用 图像视图用于显示单个图像或动画序列的图像。 重要的属性 image highlightedImage userInteractionEnabled animationImages animationRepeatCount 重要的方法 – (id)initWithImage:(UIImage *)image – (id)initWithImage:(UIImage *)image highlightedImage: (UIImage *)highlightedImage – (void)startAnimating – (void)stopAnimating 添加自定义方法 addImageView -(void)addImageView{ UIImageView *imgview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 300, 400)]; [imgview setImage:[UIImage imageNamed:@”AppleUSA1.jpg”]]; [imgview setContentMode:UIViewContentModeScaleAspectFit]; [self.view addSubview:imgview]; } 添加另一个自定义方法 addImageViewWithAnimation 这种方法解释了如何对imageView…


