您无法使用情节提要重用 UIView,您需要做的是子类 UIView [说我们将其命名为 CustomView] 并在 (void)awakeFromNib 方法中,您可以添加SubViews 并进行设计,例如,将背景颜色设置为界面视图。
您可以在情节提要中使用此子类,重用它来为您想要的任何 UIViewController 呈现相同的 UIView,您只需在 UIViewController 的 UIView 的 IdentityInspector 中将类从 UIView 设置为 CustomView。
示例自定义 UIView 类
#import "CustomView.h"
@implementation CustomView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
UIImage *bgImage = [[UIImage imageNamed:@"bg"] resizableImageWithCapInsets:UIEdgeInsetsMake(20.0, 0.0, 20.0, 0.0)];
UIImageView *bgImageView;
bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, viewHeight(self))];
[bgImageView setImage:bgImage];
[self addSubview:bgImageView];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end