IOS开发从hello world开始

学习软件开发少不了讲解hello world,ios hello world小程序对大家肯定没有什么问题了,在这里我用纯代码的方式建立一个Hello world工程,以供ios开发初学者参考了,

首先打开Xcode新建一个empty Application模版,之所以建成空模板是为了从头开始建立一个类似于SingleView Application的模版,然大家熟悉一下建立一个单个窗口程序的过程

建好后项目如下图

接下来需要创建一个基于UIViewController的视图控制器类,取名HelloWroldViewController,

HelloWroldViewController控制着程序的视图,在该类的头文件中添加如下代码以新建一个button,

#import <UIKit/UIKit.h>

@interface HelloWroldViewController : UIViewController
{
    UIButton * helloworldButton;
}
@property(nonatomic,retain)UIButton * helloworldButton;
@end

 

 

HelloWroldViewController.m中添加如下代码 

@synthesize helloworldButton = _helloworldButton;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    //设置按钮的外观类型
    self.helloworldButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    //设置按钮的位置
    self.helloworldButton.frame = CGRectMake(120, 300, 100, 40);
    //设置按钮标题
    [self.helloworldButton setTitle:@"hello world" forState:UIControlStateNormal];
    
    [self.helloworldButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    [self.view addSubview:self.helloworldButton];
    [self.helloworldButton release];
    
      
}

 

 接下来转到

AppDelegate.h添加如下代码,

@class HelloWroldViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property(nonatomic,retain)HelloWroldViewController * rootViewController;

@end

AppDelegate.m文件里引入

#import "HelloWroldViewController.h"
@implementation AppDelegate
@synthesize rootViewController = _rootViewController;
- (void)dealloc
{
    [_window release];
    [_rootViewController release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

self.rootViewController = [[HelloWroldViewController alloc]initWithNibName:nil bundle:nil];
    self.window.rootViewController = self.rootViewController;
    [self.window makeKeyAndVisible];
    return YES;
}

最后项目运行图 

转载于:https://www.cnblogs.com/X-Code/archive/2013/01/09/2853511.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值