表格视图的使用 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…
Tag: iOS
滚动视图的使用 如果内容超出屏幕的大小就会使用到滚动视图来显示隐藏的部分。 它可以包含所有的其他用户界面元素 如图像视图、 标签、 文本视图甚至另一个滚动视图。 重要的属性 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…
IOS选项卡栏的使用 它一般用于在同一视图中各个子任务、 视图或的模型之间切换。 选项卡栏的示例如下所示: 重要的属性 backgroundImage items selectedItem 示例代码和步骤 1. 创建一个新的项目,选择 Tabbed Application 替代视图应用程序 ,点击下一步, 输入项目名称和选择 create. 2. 这里默认创建两个视图控制器和标签栏添加到我们的应用程序。 3. AppDelegate.m didFinishLaunchingWithOptions方法如下: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. UIViewController *viewController1 = [[FirstViewController alloc] initWithNibName:@”FirstViewController”…
IOS导航栏的使用 导航栏包含导航控制器的导航的按钮。在导航栏中的标题是当前视图控制器的标题。 示例代码和步骤 1.创视图应用程序 2. 现在,选择应用程序 Delegate.h ,添加导航控制器的属性,如下所示: #import <UIKit/UIKit.h> @class ViewController; @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @property (strong, nonatomic) ViewController *viewController; @property (strong, nonatomic) UINavigationController *navController; @end 3. 更新应用程序: didFinishLaunchingWithOptions:方法,在AppDelegate.m文件分配的导航控制器,并使其成为窗口的根视图控制器,如下所示: – (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame: [[UIScreen…
工具栏的使用 我们可以使用工具栏修改视图元素。 如,邮件应用程序里的收件箱栏中有删除、分享、答复等等。如下所示: 重要的属性 barStyle items 添加自定义方法 addToolbar -(void)addToolbar { UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *customItem1 = [[UIBarButtonItem alloc] initWithTitle:@”Tool1″ style:UIBarButtonItemStyleBordered target:self action:@selector(toolBarItem1:)]; UIBarButtonItem *customItem2 = [[UIBarButtonItem alloc] initWithTitle:@”Tool2″ style:UIBarButtonItemStyleDone target:self action:@selector(toolBarItem2:)]; NSArray *toolbarItems = [NSArray arrayWithObjects: customItem1,spaceItem, customItem2, nil]; UIToolbar *toolbar…
状态栏的使用 状态栏显示设备的关键信息。 设备模型或网络提供商 网络信号强度 电池使用量 时间 状态栏如下所示: 隐藏状态栏的方法 [[UIApplication sharedApplication] setStatusBarHidden:YES]; 另一种隐藏状态栏的方法 我们还可以通过添加行,并在info.plist 的帮助下选择 UIStatusBarHidden 隐藏状态栏,并使其值为否(NO)。 在类中添加自定义方法 hideStatusbar 它隐藏状态栏进行动画处理,并也调整我们认为占据状态栏空间的大小。 -(void)hideStatusbar{ [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade]; [UIView beginAnimations:@”Statusbar hide” context:nil]; [UIView setAnimationDuration:0.5]; [self.view setFrame:CGRectMake(0, 0, 320, 480)]; [UIView commitAnimations]; } 在 ViewController.m 中更新 viewDidLoad,如下所示: – (void)viewDidLoad { [super viewDidLoad]; // The method hideStatusbar called…
标签的使用 标签用于显示静态内容,包括单独的一行或多行。 重要的属性 textAlignment textColor text numberOflines lineBreakMode 添加自定义方法 addLabel -(void)addLabel{ UILabel *aLabel = [[UILabel alloc]initWithFrame: CGRectMake(20, 200, 280, 80)]; aLabel.numberOfLines = 0; aLabel.textColor = [UIColor blueColor]; aLabel.backgroundColor = [UIColor clearColor]; aLabel.textAlignment = UITextAlignmentCenter; aLabel.text = @”This is a sample text\n of multiple lines. here number…
按钮使用 按钮用于处理用户操作。它截取触摸事件,并将消息发送到目标对象。 圆角矩形按钮 在 xib 中的按钮属性 您可以在Utility area(实用区域,窗口的右侧)的属性检查器的更改 xib 按钮属性。 按钮类型 UIButtonTypeCustom UIButtonTypeRoundedRect UIButtonTypeDetailDisclosure UIButtonTypeInfoLight UIButtonTypeInfoDark UIButtonTypeContactAdd 重要的属性 imageView titleLabel 重要的方法 + (id)buttonWithType:(UIButtonType)buttonType – (UIImage *)backgroundImageForState:(UIControlState)state – (UIImage *)imageForState:(UIControlState)state – (void)setTitle:(NSString *)title forState:(UIControlState)state – (void)addTarget:(id)target action:(SEL)action forControlEvents: (UIControlEvents) controlEvents 添加自定义方法 addDifferentTypesOfButton -(void)addDifferentTypesOfButton { // A rounded Rect button…
为什么使用不同的输入类型? 键盘输入的类型帮助我们从用户获取必需的输入。 它移除不需要的键,并包括所需的部分。用户可以通过使用 UITextField 的键盘属性设置输入的类型。 如:文本字段( textField)。 keyboardType = UIKeyboardTypeDefault 键盘输入类型 输入的类型 描述 UIKeyboardTypeASCIICapable 键盘包括所有标准的 ASCII 字符。 UIKeyboardTypeNumbersAndPunctuation 键盘显示数字和标点。 UIKeyboardTypeURL 键盘的 URL 项优化。 UIKeyboardTypeNumberPad 键盘用于 PIN 输入和显示一个数字键盘。 UIKeyboardTypePhonePad 键盘对输入电话号码进行了优化。 UIKeyboardTypeNamePhonePad 键盘用于输入姓名或电话号码。 UIKeyboardTypeEmailAddress 键盘对输入电子邮件地址的优化。 UIKeyboardTypeDecimalPad 键盘用来输入十进制数字。 UIKeyboardTypeTwitter 键盘对 twitter @ 和 # 符号进行了优化。 添加自定义方法 addTextFieldWithDifferentKeyboard -(void) addTextFieldWithDifferentKeyboard{ UITextField *textField1= [[UITextField alloc]initWithFrame: CGRectMake(20, 50, 280, 30)]; textField1.delegate = self; textField1.borderStyle…


