欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

IOS开发(55)之为普通App添加Storyboard

程序员文章站 2023-11-07 11:06:10
1 前言 如果我们原来的项目中没有storyboard,不要着急,我们今天就来教你如何添加storyboard。 2 代码实例 2.1 在原来项目中新建一个storyboar...

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];
}