Believe in your own future, will thank yourself right now Sinner Yun

Sinner_Yun

IOS应用程序的生命周期

 

//应用程序分类:

//ios本地应用程序: 利用iphone软件开发包(SDK)开发的本地应用程序

//web应用程序: 在web中显现的应用程序

 

//开发环境及工具

//1. xcode :编辑及调试代码文本

//2. interface builder: 可视化UI接口创建工具

//3. instruments : 调试分析应用程序, 分析内存等

//4. simulator : 模拟手机的运行环境

//5. SDK: iphone软件开发包

 

//开发方式: 手动创建   xib创建

 

//沙盒(sandBox)

//出于安全考虑,为每个应用程序在系统中创建独立文件系统机制,称为沙盒,也就是说, 每一个应用程序都是独立的存在

//应用程序之间的数据不能共享

 

//应用程序生命周期

 

 

 

 //创建一个视图,UI中的绝大多数都是继承自UIView的

 

    UIView *view = [[UIView alloc] init];

 

    

 

    //设置view的展示区域,前2位代表坐标,后2位代表大小

 

    view.frame = CGRectMake(10, 30, 100, 100);

 

    

 

    //设置view的背景色

 

    view.backgroundColor = [UIColor redColor];

 

    

 

    //在一个视图的上面,添加另外一个视图

 

    [self.window addSubview:view];

 

    

 

    //设置、查询中心点坐标

 

    view.center = self.window.center;

 

    

 

    //设置透明度

 

    view.alpha = 0.5f;

 

    

 

    //设置隐藏状态

 

    view.hidden = NO;

 

    

 

    //从父视图中移除(就不能在用了),自杀

 

    [view removeFromSuperview];

 

 

 

    //不允许子视图的范围超过自己

    bigView.clipsToBounds = YES;

 

 

//创建一个标签(是继承自UIView的)

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 60, 280, 100)];

    label.backgroundColor = [UIColor yellowColor];

    

    //设置文字

    label.text = @"I am a shuaige";

    

    //文字颜色

    label.textColor = [UIColor magentaColor];

    

    //左右对齐方式

    label.textAlignment = NSTextAlignmentRight;

    

    //文字阴影色,和阴影偏移量

//    label.shadowColor = [UIColor blackColor];

//    label.shadowOffset = CGSizeMake(2, -2);

    

    //让大小调整为单行展示文字所需要的大小

//    [label sizeToFit];

    

    //行数,写成0代表自动换行。默认是1

    label.numberOfLines = 0;

    

    //折行方式,省略号出现的位置

    label.lineBreakMode = NSLineBreakByTruncatingHead;

    

    //设置字体,普通、粗体、斜体

    label.font = [UIFont systemFontOfSize:10];

    label.font = [UIFont boldSystemFontOfSize:17];

    label.font = [UIFont italicSystemFontOfSize:17];

    

    for (NSString *str in [UIFont familyNames]) {

        NSLog(@"%@",str);

    }

    

    //使用固定字体

    label.font = [UIFont fontWithName:@"Zapfino" size:14];

 

 

 ——————————————————————————————分割———————————————————————————

@implementation AppDelegate

 

@synthesize managedObjectContext = _managedObjectContext;

@synthesize managedObjectModel = _managedObjectModel;

@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;

 

 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    // Override point for customization after application launch.

    

    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(10, 30, 300, 30)];

    view.backgroundColor = [UIColor redColor];

    [self.window addSubview:view];

    [view release];

    

    

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    NSLog(@"funtion %@ is calling", NSStringFromSelector(_cmd));

    return YES;

}

//欧路词典

 

//程序即将进入后台模式调用

- (void)applicationWillResignActive:(UIApplication *)application

{

    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

    //当应用程序从激活状态切换到非激活状态, 这个方法被调用;

    //发生中断事件的时候, 这个方法也会被调用,如:电话接入, 收到短信

    //或者用户退出应用程序切换到后台模式这个方法也被调用

    

    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

    //用这个方法暂停正在进行的任务,停止定时器,降低OpenGL ES帧率,暂停游戏

    

    NSLog(@"funtion %@ is calling", NSStringFromSelector(_cmd));

}

//进入后台后调用

- (void)applicationDidEnterBackground:(UIApplication *)application

{

    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

    //用这个方法释放共享资源保存用户数据,失效定时器,存储足够的应用程序状态信息用来恢复你的应用程序到当时的状态在应用程序随后被终止的时候

    

    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

    //如果你的程序支持后台执行, 这个方法会替换applicationWillTerminate:

    

    NSLog(@"funtion %@ is calling", NSStringFromSelector(_cmd));

}

 

//程序将要进入前台

- (void)applicationWillEnterForeground:(UIApplication *)application

{

    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

    //从后台切换到前台被调用

    //执行的动作与从前台切换到后台的动作相反

    

    NSLog(@"funtion %@ is calling", NSStringFromSelector(_cmd));

}

 

//切换到前台

- (void)applicationDidBecomeActive:(UIApplication *)application

{

    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

    //重启被暂停的任务, 如果应用程序之前在后台,有选择的刷新UI

    

    NSLog(@"funtion %@ is calling", NSStringFromSelector(_cmd));

}

 

- (void)applicationWillTerminate:(UIApplication *)application

{

    // Saves changes in the application's managed object context before the application terminates.

    //保存程序终止前的数据

    

    [self saveContext];

    NSLog(@"funtion %@ is calling", NSStringFromSelector(_cmd));

}

 

 

 

——————————————————————————————分割———————————————————————————

 

// Override point for customization after application launch.

    //通常应用程序只有一个窗口(window)

    //UIWindow 继承与 UIView

    //UIView是视图类的基类

    //UIWindow 跟UIView 配合显示内容

    

    //frame: 相对于父视图计算的坐标系

    //bounds: 直接以ios系统坐标计算的位置

    

    //状态栏 占大小是 20

    NSLog(@"width: %f, heigth: %f", self.window.frame.size.width, self.window.frame.size.height);

//    UIScreen *screen = [UIScreen mainScreen];

//    NSLog(@"screen = %@", screen);

    

    //CGPoint point = CGPointMake(10, 10);

    //CGSize size = CGSizeMake(100, 50);

    

    UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(10, 30, 300, 50)];

    

    view1.backgroundColor = [UIColor blueColor];

    [self.window addSubview:view1];//引用计数+1

    [view1 release];

    

    UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(10, 100, 300, 50)];

    view2.backgroundColor = [UIColor cyanColor];

    [self.window addSubview:view2];

    [view2 release];

    

    //设置window背景颜色

    self.window.backgroundColor = [UIColor whiteColor];

    //使window可见

    [self.window makeKeyAndVisible];

    return YES;

}

 

——————————————————————————————分割———————————————————————————

 

// Override point for customization after application launch.

    //标签:显示文字,不可以对文字编辑

    //UILabel是UIView的子类

    

    UILabel *label1 = [[UILabel alloc] init];

    label1.frame = CGRectMake((320-300)/2.0, 30, 300, 30);

    //设置标签内容

    label1.text = @"标签1: Label";

    //设置背景颜色

    label1.backgroundColor = [UIColor redColor];

    [self.window addSubview:label1];

    [label1 release];

    

    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, 300, 30)];

    label2.text = @"标签2: Label";

    label2.backgroundColor = [UIColor greenColor];

    //设置文字颜色

    label2.textColor = [UIColor whiteColor];

    //设置文字居中

    label2.textAlignment = NSTextAlignmentCenter;

    //设置文字字体及大小

    label2.font = [UIFont systemFontOfSize:25];

    [self.window addSubview:label2];

    [label2 release];

    //遍历字体库

    NSArray *familyFont = [UIFont familyNames];

    for (NSString * familyName in familyFont) {

        NSArray *names = [UIFont fontNamesForFamilyName:familyName];

        for (NSString *fontName in names) {

            NSLog(@"fontName : %@", fontName);

        }

    }

    

    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(10, 110, 300, 30)];

    label3.text = @"标签3: Label";

    label3.textAlignment = NSTextAlignmentCenter;

    label3.textColor  = [UIColor blueColor];

    label3.backgroundColor = [UIColor yellowColor];

    label3.font = [UIFont systemFontOfSize:22];

    //设置阴影颜色

    label3.shadowColor = [UIColor blackColor];

    //设置阴影偏移量

    label3.shadowOffset = CGSizeMake(3, -3);

    

    //设置字体及字号, 默认字号17

    label3.font = [UIFont fontWithName:@"GillSans-Italic" size:23];

    

    [self.window addSubview:label3];

    [label3 release];

    

    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(10, 150, 300, 50)];

    //设置透明色

    label4.backgroundColor = [UIColor clearColor];

    label4.text = @"qianfeng jiaoyu label I love chineseword World english math qianfeng qianfeng qianfeng qianfeng qianfeng qianfeng qianfeng qianfeng qianfeng qianfeng qianfeng";

    label4.backgroundColor = [UIColor orangeColor];

    //label4.textAlignment   = NSTextAlignmentCenter;

    //不限制文字显示行数

    label4.numberOfLines = 0;

    //自适应文字大小

    //label4.adjustsFontSizeToFitWidth  = YES;

    //省略中间的内容

    label4.lineBreakMode = NSLineBreakByTruncatingMiddle;

    [self.window addSubview:label4];

    [label4 release];

    

    //

    UILabel *label5 = [[UILabel alloc] initWithFrame:CGRectMake(10, 210, 300, 100)];

    label5.text = @"UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel UILabel ";

    label5.backgroundColor =[UIColor greenColor];

    label5.numberOfLines   = 0;

    label5.lineBreakMode = NSLineBreakByCharWrapping;

    [self.window addSubview:label5];

    [label5 release];

    

    

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

}

 

——————————————————————————————分割———————————————————————————

国际象棋棋盘

// Override point for customization after application launch.

    [self printChessLabel];

    

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

}

 

- (void)printChessLabel

{

    NSLog(@"size = %f", self.window.frame.size.width);

    NSArray *array = [[NSArray alloc] initWithObjects:@"車",@"🐴",@"🐘",@"王",@"后",@"🐘",@"🐴",@"車", nil];

    for (NSInteger i =0;i<8; i++) {

        for (NSInteger j =0; j<8; j++) {

            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(40*j,40*i+20, 40, 40)];

            if ((i+j)%2) {

                label.backgroundColor = [UIColor greenColor];

            }

            else

            {

                label.backgroundColor = [UIColor yellowColor];

            }

            

            //设置文字

            if (i==0 || i==7) {

                label.text = array[j];

            }

            if (i==1 || i==6) {

                label.text = @"兵";

            }

            

            label.textAlignment = NSTextAlignmentCenter;

            

            //设置字体颜色

            if (i==0 || i==1) {

                label.textColor = [UIColor redColor];

            }

            

            if (i==6 || i==7) {

                label.textColor = [UIColor blueColor];

            }

            

            [self.window addSubview:label];

            [label release];

        }

    }

 

 

}

 

posted on 2014-03-13 20:24  Sinner_Yun  阅读(293)  评论(0编辑  收藏  举报

导航