在故事板中显示自定义UIView

时间:2017-07-03 10:06:26

标签: ios uiview storyboard subclass

我找到了这个自定义UIView here

现在,我想将它添加到myViewController。 我做了什么:

在myViewController.h中我有:

#import <UIKit/UIKit.h>
#import "CJGGridView.h"
@class CJGGridView;
@interface ViewController : UIViewController
@property (nonatomic, strong) IBOutlet CJGGridView * theBoard;
@end

在故事板上,我放置了一个UIView并将其定义为自定义类&#34; CJGridView&#34; 然后我将它连接到&#34; theBoard&#34;。为了轻松区分View,我给它一个橙色背景色。

myViewController.m中的

我有:

- (void)viewDidLoad {
    [super viewDidLoad];
    theBoard = [[CJGGridView alloc]initWithSquareSize:self.theBoard.frame.size.width/8];
}

现在,当我运行应用程序时,我确实看到一个橙色方块,左上角有一些渐变。

但是,我没有看到我期望的网格。

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

你在viewdidload中直接初始化

- (void)viewDidLoad {
    [super viewDidLoad];
    theBoard = [CJGGridView initWithSquareSize:self.theBoard.frame.size.width/8];
}