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”…

状态栏的使用 状态栏显示设备的关键信息。 设备模型或网络提供商 网络信号强度 电池使用量 时间 状态栏如下所示: 隐藏状态栏的方法 [[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…

工具栏的使用 我们可以使用工具栏修改视图元素。 如,邮件应用程序里的收件箱栏中有删除、分享、答复等等。如下所示: 重要的属性 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…

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…

标签的使用 标签用于显示静态内容,包括单独的一行或多行。 重要的属性 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…

文本字段的使用 文本字段是一个用户界面元素,通过应用程序来获取用户输入。 一个UITextfield如下所示: 重要的文本字段的属性 在没有任何用户输入时,显示占位符 正常文本 自动更正型 键盘类型 返回键类型 清除按钮模式 对齐方式 委托 更新xib中的属性 可以在Utility area(实用区域,窗口的右侧)更改xib在属性查看器中的文本字段属性。 文本字段委托 我们可以通过右击 UIElement 界面生成器中设置委托并将它连接到文件的所有者,如下所示: 使用委托的步骤: 1.设置委托如上图所示 2.添加委托到您的响应类 3.执行文本字段代表,重要的文本字段代表如下: – (void)textFieldDidBeginEditing:(UITextField *)textField – (void)textFieldDidEndEditing:(UITextField *)textField 4.正如其名称所暗示,上述两个委托分别叫做编辑的文本字段和结束编辑 5. 其他的委托请查看 UITextDelegate Protocol 参考手册。 实例 以下我们使用简单的实例来创建UI元素 ViewController 类将采用UITextFieldDelegate,修改ViewController.h文件,如下所示: 将方法addTextField添加到我们的 ViewController.m 文件 然后在 viewDidLoad 方法中调用此方法 在ViewController.m中更新viewDidLoad,如下所示 #import…

什么是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-选项卡栏…

委托(Delegates)示例 假设对象A调用B来执行一项操作,操作一旦完成,对象A就必须知道对象B已完成任务且对象A将执行其他必要操作。 在上面的示例中的关键概念有 A是B的委托对象 B引用一个A A将实现B的委托方法 B通过委托方法通知 创建一个委托(Delegates)对象 1. 创建一个单一视图的应用程序 2. 然后选择文件 File -> New -> File… 3. 然后选择Objective C单击下一步 4. 将SampleProtocol的子类命名为NSObject,如下所示 5. 然后选择创建 6.向SampleProtocol.h文件夹中添加一种协议,然后更新代码,如下所示: #import <Foundation/Foundation.h> // 协议定义 @protocol SampleProtocolDelegate <NSObject> @required – (void) processCompleted; @end // 协议定义结束 @interface SampleProtocol : NSObject { //…