IOS在界面生成器中使用继承视图
为了创建更圆的图像视图,我扩展了UIImageView:IOS在界面生成器中使用继承视图,ios,inheritance,uiimageview,interface-builder,Ios,Inheritance,Uiimageview,Interface Builder,为了创建更圆的图像视图,我扩展了UIImageView: #import <QuartzCore/QuartzCore.h> #import "RoundedImageView.h" @implementation RoundedImageView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self makeImageVie
#import <QuartzCore/QuartzCore.h>
#import "RoundedImageView.h"
@implementation RoundedImageView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self makeImageViewRounded];
}
return self;
}
-(void) makeImageViewRounded {
self.layer.backgroundColor=[[UIColor clearColor] CGColor];
self.layer.cornerRadius=20;
self.layer.borderWidth=1.0;
self.layer.masksToBounds = YES;
self.layer.borderColor=[[UIColor whiteColor] CGColor];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
#导入
#导入“RoundedImageView.h”
@实现RoundedImageView
-(id)initWithFrame:(CGRect)帧
{
self=[super initWithFrame:frame];
如果(自我){
[自行制作图像];
}
回归自我;
}
-(void)makeImageViewRounded{
self.layer.backgroundColor=[[UIColor clearColor]CGColor];
自层转角半径=20;
self.layer.borderWidth=1.0;
self.layer.masksToBounds=是;
self.layer.borderColor=[[UIColor whiteColor]CGColor];
}
/*
//仅覆盖drawRect:如果执行自定义绘图。
//空实现会对动画期间的性能产生不利影响。
-(void)drawRect:(CGRect)rect
{
//绘图代码
}
*/
@结束
在故事板中,我已将UIImageView连接到我的自定义RoundImageView,
但它似乎不会影响视图,而且我的代码也不会被调用
当我将自定义视图附加到UIView时,自定义视图将被初始化,我如何使其工作?在从情节提要创建视图时覆盖此初始化器:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder: aDecoder];
if (self) {
[self makeImageViewRounded];
}
return self;
}
这是因为将调用“initWithCoder:(NSCoder*)aDecoder”初始值设定项。太棒了!把它写下来作为回答,这样我就可以接受了