在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
cocoa
类: 传统的写法: // // Demo.h // demoClass // // Created by 王 on 13-12-16. // Copyright (c) 2013年 Bo Li. All rights reserved. // #import <Foundation/Foundation.h> @interface Demo : NSObject { int age; int ide; NSString *name; } //初始化方法 -(id)initWithAge:(int)_age andIde:(int)_ide andName:(NSString *)_name; -(void)setAge:(int)_age; -(int)getAge; -(void)setIde:(int)_ide; -(int)getIde; -(void)setName:(NSString *)_name; -(NSString *)getName; @end Demo.m // // Demo.m // demoClass // // Created by 王 on 13-12-16. // Copyright (c) 2013年 Bo Li. All rights reserved. // #import "Demo.h" @implementation Demo //初始化方法,只有[super init]初始化父类成功后子类才能初始化 -(id)initWithAge:(int)_age andIde:(int)_ide andName:(NSString *)_name{ if(self = [super init]){ age = _age; ide = _ide; name = _name; } return self; } -(void)setAge:(int)_age{ age = _age; } -(int)getAge{ return age; } -(void)setIde:(int)_ide{ ide = _ide; } -(int)getIde{ return ide; } -(void)setName:(NSString *)_name{ name = _name; } -(NSString *)getName{ return name; } @end main.m // // main.m // demoClass // // Created by 王 on 13-12-10. // Copyright (c) 2013年 Bo Li. All rights reserved. // #import <Foundation/Foundation.h> #import "Test.h" #import "Demo.h" int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); Demo *d = [[Demo alloc] initWithAge:15 andIde:212321 andName:@"lily"]; NSLog(@"she is %d,and hers identify is %d,she names %@",[d getAge],[d getIde],[d getName]); } return 0; } OC特有的用法(设置器@property和访问器@synthesize) // // Demo.h // demoClass // // Created by 王 on 13-12-16. // Copyright (c) 2013年 Bo Li. All rights reserved. // #import <Foundation/Foundation.h> @interface Demo : NSObject { int age; int ide; NSString *name; } //初始化方法 -(id)initWithAge:(int)_age andIde:(int)_ide andName:(NSString *)_name; @property(nonatomic) int age; @property(nonatomic) int ide; @property(nonatomic,retain) NSString *name; @end Demo.m // // Demo.m // demoClass // // Created by 王 on 13-12-16. // Copyright (c) 2013年 Bo Li. All rights reserved. // #import "Demo.h" @implementation Demo //初始化方法,只有[super init]初始化父类成功后子类才能初始化 -(id)initWithAge:(int)_age andIde:(int)_ide andName:(NSString *)_name{ if(self = [super init]){ age = _age; ide = _ide; name = _name; } return self; } @synthesize age; @synthesize ide; @synthesize name; @end main.m // // main.m // demoClass // // Created by 王 on 13-12-10. // Copyright (c) 2013年 Bo Li. All rights reserved. // #import <Foundation/Foundation.h> #import "Test.h" #import "Demo.h" int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); Demo *d = [[Demo alloc] initWithAge:15 andIde:212321 andName:@"lily"]; NSLog(@"she is %d,and hers identify is %d,she names %@",[d age],[d ide],[d name]); } return 0; } 备注:
点语法:(看下面代码即可明白) // // main.m // demoClass // // Created by 王 on 13-12-10. // Copyright (c) 2013年 Bo Li. All rights reserved. // #import <Foundation/Foundation.h> #import "Test.h" #import "Demo.h" int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); Demo *d = [[Demo alloc] initWithAge:15 andIde:212321 andName:@"lily"]; d.age = 10; d.name = @"hhaa"; NSLog(@"she is %d,and hers identify is %d,she names %@",[d age],[d ide],[d name]); } return 0; }
static关键字: static int count = 1000; 要点: UIKIT UIView:视图的基础, 窗口(UIWindow): UIScreen:获取硬件设备的屏幕尺寸,在做适配的时候用到,比如iphone的屏幕和ipad的屏幕。 IOS坐标系统: CGPoint potin = CGPointMake(x,y);//位置 Frame,Bounds,Center: 创建视图: //通过xib的方式来创建视图对象 NSBundle *bundle = [NSBundle mainBundle]; NSArray *arr = [bundle loadNibNamed:@"myView" owner:self options:nil]; UIView *myView = [arr objectAtIndex:0]; //通过代码创建视图对象 CGRect viewRect = CGRectMake(0, 0, 100, 100); UIView *myView = [[UIView alloc] initWithFrame:viewRect]; 视图调用方法(视图的层次关系): //基本的添加和删除子视图 addSubview: //添加子视图 insertSubview:atIndex: //视图插入到指定索引位置 insertSubview:aboveSubview: //视图插入指定视图之上 insertSubview:belowSubview: //视图插入指定视图之下 bringSubviewToFront: //把视图移动到最顶层 sendSubviewToBack: //把视图移动到最底层 exchangeSubviewAtIndex:withSubviewAtIndex: //把两个索引对应的视图调换位置 removeFromSuperview: //把视图从父视图中移除 备注:当调用addSubview的时候会对其进行保留,可理解为retain一个对象; |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论