在故事板中显示自定义 UIView
Displaying a custom UIView in a storyboard
我找到了这个自定义 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 并将其定义为自定义 class "CJGridView"
然后我将它连接到 "theBoard"。为了方便区分View,我给它设置了橙色背景色。
在 myViewController.m 我有:
- (void)viewDidLoad {
[super viewDidLoad];
theBoard = [[CJGGridView alloc]initWithSquareSize:self.theBoard.frame.size.width/8];
}
现在,当我 运行 应用程序时,我确实看到了一个橙色方块,左上角有某种渐变。
但是,我没有看到预期的网格。
我做错了什么?
你直接在viewdidload中初始化
- (void)viewDidLoad {
[super viewDidLoad];
theBoard = [CJGGridView initWithSquareSize:self.theBoard.frame.size.width/8];
}
我找到了这个自定义 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 并将其定义为自定义 class "CJGridView" 然后我将它连接到 "theBoard"。为了方便区分View,我给它设置了橙色背景色。
在 myViewController.m 我有:
- (void)viewDidLoad {
[super viewDidLoad];
theBoard = [[CJGGridView alloc]initWithSquareSize:self.theBoard.frame.size.width/8];
}
现在,当我 运行 应用程序时,我确实看到了一个橙色方块,左上角有某种渐变。
但是,我没有看到预期的网格。
我做错了什么?
你直接在viewdidload中初始化
- (void)viewDidLoad {
[super viewDidLoad];
theBoard = [CJGGridView initWithSquareSize:self.theBoard.frame.size.width/8];
}