你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> IOS開發(55)之為普通App添加Storyboard

IOS開發(55)之為普通App添加Storyboard

編輯:IOS開發綜合

1 前言
如果我們原來的項目中沒有Storyboard,不要著急,我們今天就來教你如何添加Storyboard。

2 代碼實例
2.1 在原來項目中新建一個Storyboard

 

2.2 選擇設備類型

 

2.3 設置Storyboard的名稱

 

2.4 在AddStoryboardTest-Info.plist中添加節點   UIMainStoryboardFile 值為Storyboard的名字:iPhone

 

2.5 在Storyboard中添加View視圖,並將其Class設置為已有的Controller的名字

 

ZYViewController.h

 

[plain]
#import <UIKit/UIKit.h> 
 
@interface ZYViewController : UIViewController 
 
@property(nonatomic,strong) UILabel *myLabel; 
 
@end 

#import <UIKit/UIKit.h>

@interface ZYViewController : UIViewController

@property(nonatomic,strong) UILabel *myLabel;

@end
ZYViewController.m

 

[plain]

@synthesize myLabel; 
 
- (void)viewDidLoad 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    // Do any additional setup after loading the view, typically from a nib. 
    self.view.backgroundColor = [UIColor whiteColor]; 
    //    CGRect labelFrame = CGRectMake(0.0f, 0.0f, 100.0f, 23.0f); 
    CGRect labelFrame = CGRectMake(0.0f, 0.0f, 100.0f, 50.0f); 
    self.myLabel = [[UILabel alloc] initWithFrame:labelFrame]; 
    self.myLabel.numberOfLines = 3;//分三行 
    self.myLabel.text = @"Archy is Studying IOS 5 Programming";//label的文字 
    self.myLabel.font = [UIFont boldSystemFontOfSize:14.0f];//字體樣式 
    self.myLabel.center = self.view.center;//UILabel控件居中 
    [self.view addSubview:self.myLabel]; 

@synthesize myLabel;

- (void)viewDidLoad
{
    [super viewDidLoad];
 // Do any additional setup after loading the view, typically from a nib.
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    //    CGRect labelFrame = CGRectMake(0.0f, 0.0f, 100.0f, 23.0f);
    CGRect labelFrame = CGRectMake(0.0f, 0.0f, 100.0f, 50.0f);
    self.myLabel = [[UILabel alloc] initWithFrame:labelFrame];
    self.myLabel.numberOfLines = 3;//分三行
    self.myLabel.text = @"Archy is Studying IOS 5 Programming";//label的文字
    self.myLabel.font = [UIFont boldSystemFontOfSize:14.0f];//字體樣式
    self.myLabel.center = self.view.center;//UILabel控件居中
    [self.view addSubview:self.myLabel];
}
 

 

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved