[英]IOS use inherited View inside interface builder
I've extended UIImageView inorder to create a rounder image view: 我扩展了UIImageView以便创建更圆的图像视图:
#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
In the story board i've connected an UIImageView to my custom RoundedImageView, But it doesn't seems to affect the view, and my code doesn't get called. 在故事板上,我已经将UIImageView连接到我的自定义RoundedImageView,但是它似乎并没有影响视图,也没有调用我的代码。
How can i make it work that whenever i attach an custom view to my UIView, the custom view will be initialised ? 我如何使每当我将自定义视图附加到UIView时,都会初始化该自定义视图?
Override this initializer when creating views from storyboard: 从情节提要板创建视图时,请重写此初始化程序:
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder: aDecoder];
if (self) {
[self makeImageViewRounded];
}
return self;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.