没有办法,你可以用故事板重用一个UIView,你需要做的是子类的UIView [说我们把它命名到CustomView]和(无效)awakeFromNib方法,你可以addSubViews并做设计的东西,设置背景颜色为UIView。
你可以在故事板中使用这个子类,重用它来为你想要的任何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
阅读我的问题中的第一个*。我正在寻找一种方法来做到这一点,仍然使用接口生成器 – Segev
设计'UIView'我想出来了,而不是使用awakeFromNib,你可以为CustomView添加一个nib文件。然后在相应UIViewController的文件检查器中使用此CustomView类而不是UIView http://i40.tinypic.com/a9widx.jpg – Say2Manuj
这是我的问题中的第二个*。你应该花时间仔细阅读问题。 – Segev