表格视图的使用 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…
Category: Mobile
分割视图的使用 分割视图是 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选项卡栏的使用 它一般用于在同一视图中各个子任务、 视图或的模型之间切换。 选项卡栏的示例如下所示: 重要的属性 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”…
图像视图的使用 图像视图用于显示单个图像或动画序列的图像。 重要的属性 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…
工具栏的使用 我们可以使用工具栏修改视图元素。 如,邮件应用程序里的收件箱栏中有删除、分享、答复等等。如下所示: 重要的属性 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…
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…
按钮使用 按钮用于处理用户操作。它截取触摸事件,并将消息发送到目标对象。 圆角矩形按钮 在 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…
标签的使用 标签用于显示静态内容,包括单独的一行或多行。 重要的属性 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…
什么是UI元素? UI元素是我们应用程序里可以看见的任何可视元素,其中一些元素响应用户的操作,如按钮、文本字段,有其他的丰富内容,如图像、标签等。 如何添加UI元素? 可以在界面生成器的参与下,在代码中添加UI元素。如果需要,我们可以使用他们其中之一。 我们关注的 通过代码,将集中于添加UI元素到应用程序。比较简单而直接的方法是使用界面生成器拖放UI元素。 方法 以下我们通过创建一款简单的IOS应用程序,来解释一些UI元素 步骤 1、在第一款IOS程序里一样,创建一个Viewbased应用程序 2、只更新ViewController.h和ViewController.m文件 3、然后我们将方法添加到ViewController.m文件中来创建UI元素 4、在viewDidLoad方法中调用此方法 5、重要的代码行已经在代码中通过在单行上方标注的方式进行了注释 用户界面元素列表 下面解释具体的UI元素和其相关的功能/p> 序号 具体的UI元素或功能 1 Text Fields-文本字段 用户界面元素,使用应用程序来获取用户输入 2 输入类型-TextFields 用户可以通过使用UITextField来赋予键盘输入属性 3 Buttons-按钮 用于处理用户操作 4 Label-标签 用于显示静态内容 5 Toolbar-工具栏 操纵当前视图所显示的东西 6 Status Bar-状态栏 显示设备的关键信息 7 Navigation Bar-导航栏 包含一个可以推断的视图控制器,并弹出导航控制器的导航按钮 8 Tab bar-选项卡栏…


