DAY
今天给你的iPhone 制作一个简单的数数程序。
-在程序显示前运行代码;
-UIButton, UILabel, UIImageView 的运用;
-把integer转换为string;
首先运行以安装好的xCode
选择: File->New Project.
从 "New Project" 窗口
选择 : iPhone OS ->Applications-> View-Based Application
命名 : 我这里命名为 “CountMeIn”
(1)
#import <UIKit/UIKit.h>
@interface CountMeInViewController : UIViewController {
}
-(IBAction)reset;
-(IBAction)addUnit;
-(IBAction)subtractUnit;
@end
(2)
#import "CountMeInViewController.h"
@implementation CountMeInViewController
int count = 0;
-(IBAction)reset{
}
- (IBAction)addUnit {
}
- (IBAction)subtractUnit {
}
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
}
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterf
}
- (void)didReceiveMemoryWarning {
}
- (void)dealloc {
}
(3) 导入下面图片文件
backgroundPattern
IconGreenAdd
IconRedSubtract
在xCode下右键点击CountMeIn->Add->Existing Files; 在countMeIn文件夹内,选择下载好的三个图片,按 Add
(4) UIView 界面设置
双击文件: "CountMeInViewController.xib" ;
然后 "Interface Builder"
(5) 加入
选择: Tools ->
在主视窗口或文件窗口;点击 Label
选择: Tools -> Connection Inspector
移动鼠标在"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "counter"; 选上它。
(6) 加入
选择: Tools ->
在主视窗口或文件窗口;点击 Button
选择: Tools -> Connection Inspector
移动鼠标在"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "addUnit"; 选上它。
选择: Tools -> Attributes Inspector
在 Type 下选择 custom; 在 Background 下选择 iconGreenAdd
选择: Tools -> Size Inspector
调整 Size & Position
(7) 加入
选择: Tools ->
在主视窗口或文件窗口;点击 Button
选择: Tools -> Connection Inspector
移动鼠标在"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "SubtractUnit"; 选上它。
选择: Tools -> Attributes Inspector
在 Type 下选择 custom; 在 Background 下选择 iconRedSubtract
选择: Tools -> Size Inspector
调整 Size & Position
(8) 加入
选择: Tools ->
在主视窗口或文件窗口;点击 Button
选择: Tools -> Connection Inspector
移动鼠标在"Touch Up Inside" 后面圆圈上; 圆圈变为(+); 拖向直线连接到"File's Owner";
放开鼠标选择键出现 "Reset"; 选上它。
选择: Tools -> Attributes Inspector
在 Title 下填上 Reset
(9) 加入
选择: Tools ->
在主视窗口或文件窗口;点击 imageView
选择: Tools ->
选择: Tools ->
最后在 xCode 选择 Build->Build and Go; Save All.
下载今天程序文件: CountMeIn.zip