iOS 学习资料整理
写在前面-(学习背景)
从去年开始就想跳入iOS开发的这个坑,从看C语言开始,到Objective-C的语法,看的很慢,效率奇低,中间穿插着瞎搞了一段时间C++,觉得什么都做不出来,又去干MFC,总算是搞出来一个垃圾的音乐播放器(这个后面也会把它写出来)。然后又拐回来跟着一个好兄弟的脚步二战OC,又是拖拖拉拉,看了忘,忘了从头来,加上自己总是找借口,找理由抵制学习。然后想到了简书,从UI控件基础重新开始,来记录我的学习进度。
首先做了一张我理解的iOS开发的简单的步骤的导图。
那么接下来就开始着手搭建第一个项目的界面-加法器。
首先创建一个工程:
修改屏幕适配4.7英寸
然后添加控件,修改控件上的内容,展示如下 (两个text 3个label 1个button)
当取得Text的焦点时,弹出数字键盘。
至此一个简单的加法器的界面搭建完毕(很简陋,但是千里之行始于足下。)commond+R 运行,查看效果。
接下来就开始编写实现加法的代码。
(代码和控件建立连接)
加法的实现代码:
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1d9421}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; min-height: 21.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c91b13}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3c828c}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c32275}p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #3d1d81}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font: 18.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures}span.s3 {font-variant-ligatures: no-common-ligatures; color: #822e0e}span.s4 {font-variant-ligatures: no-common-ligatures; color: #c32275}span.s5 {font-variant-ligatures: no-common-ligatures; color: #000000}span.s6 {font-variant-ligatures: no-common-ligatures; color: #6122ae}span.s7 {font-variant-ligatures: no-common-ligatures; color: #539aa4}span.s8 {font-variant-ligatures: no-common-ligatures; color: #703daa}span.s9 {font-variant-ligatures: no-common-ligatures; color: #3d1d81}span.s10 {font-variant-ligatures: no-common-ligatures; color: #c91b13}
//
// ViewController.m
// addApp
//
// Created by 袁跃 on 16/4/19.
// Copyright © 2016年 iflytek. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
- (IBAction)addCompute;
@property (weak, nonatomic) IBOutlet UITextField *TxtNum1;
@property (weak, nonatomic) IBOutlet UITextField *txtNum2;
@property (weak, nonatomic) IBOutlet UILabel *addResult;
@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.
}
- (IBAction)addCompute {
NSString *num1 = self.TxtNum1.text;
NSString *num2 = self.txtNum2.text;
int n1 = [num1 intValue];
int n2 = [num2 intValue];
int result = n1+n2;
self.addResult.text = [NSString stringWithFormat:@"%d",result];
[self.view endEditing:YES];
}
@end
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #1d9421}p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; min-height: 21.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c91b13}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo}p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Menlo; color: #c32275}span.s1 {font-variant-ligatures: no-common-ligatures}span.s2 {font: 18.0px 'PingFang SC'; font-variant-ligatures: no-common-ligatures}span.s3 {font-variant-ligatures: no-common-ligatures; color: #822e0e}span.s4 {font-variant-ligatures: no-common-ligatures; color: #c32275}span.s5 {font-variant-ligatures: no-common-ligatures; color: #6122ae}
//
// ViewController.h
// addApp
//
// Created by 袁跃 on 16/4/19.
// Copyright © 2016年 iflytek. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
@end
至此,加法器完成,效果如下:
(千里之行,始于足下)
集中注意力