今天讲的内容我没听太明白,感觉没有昨天那么清晰,这样总结一下,也算是归纳归纳,完了还能再看看。。。
今天讲了两个编程,结果晚上吃完晚饭一回来就忘了。。。坑
第一个是创建一个类,并实现它
首先创建一个新的文件,我将他命名为“ car ”,然后在新建的接口文件里面,定义一些该“ 类 ”事物的一些特征,例如车的话,有它的重量、价格、颜色、车名等等
但是这里会有一个点需要注意:
以下程序在 Car.h 文件中。
@public、@private、@protected
如:@interface Car :NSObject {
@public
NSString *color;
float weight;
@private
float price;
@public
NSString *name;
}
- (void)carwithspeed:(float)weight andpirection:(int)mama;
上述程序的主要功能是做一个声明。
接下来第二步的程序是在 Car.m 中实现,主要完成的功能是实现上一个声明。下面的程序很简单有一个模式:
- (void)carwithspeed(方法名) : ( float )weight(参数名1) anddirection(方法名) : ( int )mama(参数名2){
NSLog(@"carwithspeed:%.2f pirection:%d",weight,mama);
}
第一个:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// int age;
return YES;
}
第二个:
//程序现实前调用
- (void)viewDidLoad {
[super viewDidLoad];
}
最后一步的代码也较为简单: [car01 carwithspeed : 203.2837784 anddirection : 2323 ];
@implementation ViewController
//程序现实前调用
- (void)viewDidLoad {
[super viewDidLoad];
Car *car01 = [[Car alloc] init];
car01->weight= 0;
car01->name = @"QQ";
[car01 run];
[car01 carwithspeed : 203.2837784 anddirection : 2323];
}
第二个是用代码编写一面国旗
我编的是一面德国国旗,世界杯太牛了
德国国旗的编码没一种颜色只有4行:
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIView *redview = [[UIView alloc]init];
redview.frame = CGRectMake(0, 60, 130, 30);
redview.backgroundColor = [UIColor redColor];
[self.view addSubview:redview];
UIView *blackview = [[UIView alloc]init];
blackview.frame = CGRectMake(0, 30, 130, 30);
blackview.backgroundColor = [UIColor blackColor];
[self.view addSubview:blackview];
UIView *yellowview = [[UIView alloc]init];
yellowview.frame = CGRectMake(0, 90, 130, 30);
yellowview.backgroundColor = [UIColor yellowColor];
[self.view addSubview:yellowview];
UIView *redview1=[[UIView alloc]init];
redview1.frame=CGRectMake( 180, 104, 130, 16);
redview1.backgroundColor=[UIColor redColor];
[self.view addSubview:redview1];
UIView *whiteview1=[[UIView alloc]init];
whiteview1.frame=CGRectMake(180, 15, 130, 10);
whiteview1.backgroundColor=[UIColor whiteColor];
[self.view addSubview:whiteview1];
UIView *yellowview1=[[UIView alloc]init];
yellowview1.frame=CGRectMake(180, 45, 130, 43);
yellowview1.backgroundColor=[UIColor yellowColor];
[self.view addSubview:yellowview1];
UIView *blueview=[[UIView alloc]init];
blueview.frame=CGRectMake(180, 88, 130, 16);
blueview.backgroundColor=[UIColor blueColor];
[self.view addSubview:blueview];
}