iOS的书写和创作过程需要清晰的思路,你想要做什么,怎么做
首先,我们想要实现一个功能,在输入框中输入HelloWord,点击按钮,实现HelloWord传给接收框的功能。
其次,设计,界面如何设计,组建的摆放位置
再次,代码实现
至于设计的过程就不赘述,我们主要以代码为主,这里也不介绍拖控件的方法了
创建一个singleView,继承UIViewController类
在.h文件中定义接收框,输入框和按钮
// LYXViewController.h
// helloWord
//
// Created by liyongxing on 13-7-2.
// Copyright (c) 2013年 liyongxing. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface LYXViewController :UIViewController
@property (nonatomic ,strong)UILabel * lable;
@property (nonatomic ,strong)UITextField * textFile;
@property (nonatomic ,strong)UIButton * button;
@end
.m中实现功能
//
// LYXViewController.m
// helloWord
//
// Created by liyongxing on 13-7-2.
// Copyright (c) 2013年 liyongxing. All rights reserved.
//
#import "LYXViewController.h"
@interface LYXViewController ()
@end
@implementation LYXViewController
- (void)viewDidLoad
{
[superviewDidLoad];
//创建helloWord的接收框
self.lable = [[UILabelalloc]initWithFrame:CGRectMake(20,50, 200, 40)];
//设置lable的颜色
self.lable .backgroundColor = [UIColorbrownColor];
[self.viewaddSubview:self.lable ];
//-------创建一个输入框----------
self.textFile = [[UITextFieldalloc]initWithFrame:CGRectMake(20,120, 200, 40)];
//设置text的颜色
self.textFile.backgroundColor = [UIColorbrownColor];
[self.viewaddSubview:self.textFile];
//-------创建一个按钮-----------
self.button = [UIButtonbuttonWithType:UIButtonTypeRoundedRect];
self.button.frame =CGRectMake(20,180 ,50, 30);
//自定义按钮的点击事件,forControlEvents是点击的事件,后面的类型是TouchUpInside,当点击按 //钮的时候发生的事件
[self.buttonaddTarget:selfaction:@selector(pressButton)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:self.button];
}
-(void)pressButton
{
NSLog(@"%@",self.textFile.text);
self.lable.text =self.textFile.text;
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
}
@end