IOS 应用立 足的两 大要素:美观 的 UI 界面 ( 好的卖相 )和实 用的功 能
IOS开发需要掌握的内容
–语言基础:OC,C,C++(可选学),基础框架(Foundation)
iOS系统架构
iOS系统架构中各层次的功能
iOS 框架的使用策略
iOS 系统框架表格
iOS 和 android 系统架构对比
IOS应用的开发步骤:
新建项目 1 —— 选择项目模板
新建项目 2 —— 设置项目属性(注意:选择Use Storyboards与不选的区别)
新建项目 3 —— 保存项目
新建项目 4 —— 运行(command+r)
搭建界面 1—— 界面入口
搭建界面 2 —— MainStoryboard.Storyboard
搭建 界面 3 —— 显示对象库
搭建 界面 4 —— 界面搭建
搭建 界面 5 —— 两个细节
监听按钮点击事件 1—— 助理编辑器窗口
监听按钮点击 事件 2—— IBAction 告知 代码发生事件
监听按钮点击 事件 3—— 建立 IBAction
// 点击你好按钮
- (IBAction)tapHelloButton:(id)sender;
监听按钮点击 事件 4—— 准备编写代码- (IBAction)tapHelloButton:(id)sender
{
}
出现问题:
1.如何获得文本框控件?
2.如何获得文本标签控件?
ViewController.h
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
// 用户名,Outlet告诉程序可以操作对象
// 定义属性之后,Xcode会自动建立Getter & Setter方法
@property (weak,nonatomic)IBOutlet UITextField *userNameText;
// 消息标签
@property (weak,nonatomic)IBOutlet UILabel *helloLabel;
// 点按Hello按钮
- (IBAction)tapHelloButton:(id)sender;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
将结果显示在文本标签中
#pragma mark - IBActions
- (IBAction)tapHelloButton:(id)sender
{
// 通常,在一个类的内容,使用自己的属性时,为了提高效率
// 可以使用成员变量代替属性
/**
属性定义的目的,是为了其他的类访问本类时,保证内部数据安全
*/
//1. 获取文本框内容,并且拼接字符串
NSString *text = [NSStringstringWithFormat:@"你好 %@!",_userNameText.text];
//2. 将结果显示在文本标签中
[_helloLabel setText:text];
}
@end
让视图关闭键盘
- (IBAction)tapHelloButton:(id)sender
{
//1. 获取文本框中的内容
NSString *text = [NSStringstringWithFormat:@"你好 %@!",_userNameText.text];
//2. 将结果显示在标签中
[_helloLabel setText:text];
//3. 让视图关闭键盘
[self.view endEditing:YES];
}