技术宅,fat-man

增加语言的了解程度可以避免写出愚蠢的代码

导航

< 2025年6月 >
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 1 2 3 4 5
6 7 8 9 10 11 12

统计

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");
    }
}
复制代码

 

posted on 2014-08-29 00:08  codestyle  阅读(254)  评论(0)    收藏  举报

编辑推荐:
· 聊一聊 Linux 上对函数进行 hook 的两种方式
· C# 锁机制全景与高效实践:从 Monitor 到 .NET 9 全新 Lock
· 一则复杂 SQL 改写后有感
· golang中写个字符串遍历谁不会?且看我如何提升 50 倍
· C# 代码如何影响 CPU 缓存速度?
阅读排行:
· 突发,CSDN 崩了!程序员们开始慌了?
· 一个基于 .NET 8 + Ant Design Blazor 开发的简洁现代后台管理框架
· 鸿蒙Next仓颉语言开发实战教程:订单详情
· C# WinForms 实现打印监听组件
· 网易游戏DB SaaS引入OceanBase:存储成本降60%,备份恢复提速3倍
历史上的今天:
2012-08-29 500TB——Facebook每天收集的数据量
2012-08-29 rabbitmq安装
点击右上角即可分享
微信分享提示