zoukankan      html  css  js  c++  java
  • iOS版 hello,world版本2

    //
    //  main.m
    //  Hello
    //
    //  Created by lishujun on 14-8-28.
    //  Copyright (c) 2014年 lishujun. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    
    // 视图控制器对象
    @interface HelloWorldViewController : UIViewController
    @end
    
    @implementation HelloWorldViewController
    
    -(void) loadView
    {
        //创建视图对象
        UIView *contentView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen] applicationFrame]];
        contentView.backgroundColor = [UIColor lightGrayColor];
        self.view = contentView;
        
        //创建label对象
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 320.0, 30.0)];
        label.text = @"Hello World";
        label.center = contentView.center;             // 垂直居中
        label.textAlignment = UITextAlignmentCenter;   // 水平居中
        label.backgroundColor = [UIColor clearColor];
        label.textColor = [UIColor redColor];
        
        //在视图上添加label
        [contentView addSubview:label];
    }
    
    @end
    
    
    // 委托对象
    @interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate>
    {
        IBOutlet UIWindow *window;
    }
    
    @property (nonatomic, retain) UIWindow *window;
    @property (nonatomic, retain) HelloWorldViewController *viewController;
    //window 必须声明为属性,声明为局部变量则无法绘制视图,显示为黑屏
    //apple 官方文档把viewController也声明为属性了
    @end
    
    @implementation HelloWorldAppDelegate
    
    @synthesize window;
    @synthesize viewController;
    
    -(void) applicationDidFinishLaunching:(UIApplication *)application
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]bounds]];
        self.viewController = [[HelloWorldViewController alloc]init];
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
    }
    
    @end
    
    // 程序入口
    int main(int argc, char * argv[])
    {
        @autoreleasepool {
            return UIApplicationMain(argc, argv, nil, @"HelloWorldAppDelegate");
        }
    }
  • 相关阅读:
    《javascript高级程序设计》第六章总结
    电子邮件写信页面开发代码
    JSON和XML的比较
    2014前端工程师基础课程作业
    cookie 和session 的区别详解
    substring()、slice()和substr()方法辨析
    Number()、parseInt()和parseFloat()辨析
    《javascript高级程序设计》第十三章知识点
    angular debounce 搜索去抖动/防抖
    js四舍五入保留两位小数的方法
  • 原文地址:https://www.cnblogs.com/code-style/p/3943914.html
Copyright © 2011-2022 走看看