简体   繁体   English

iOS在界面生成器中使用继承的View

[英]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.

相关问题 iOS - Interface Builder - 在同一个xib中绑定多个视图 - iOS - Interface Builder - bind multiple view inside the same xib 界面生成器中的iOS阴影视图 - iOS shadow view in interface builder 如何在 iOS Interface Builder 的子文件夹中使用图像 - How to use images in subfolders in iOS Interface Builder 在 Interface Builder 中使用泛型类作为自定义视图 - Use a generic class as a custom view in Interface Builder 如何在Interface Builder文件中使用自定义iOS视图(位于引用的类库中)? - How to use a Custom iOS View(located in a referenced Class Library) in an Interface Builder file? 在iOS上,如果将Interface Builder用于UIViewController的视图,我们如何为其实现drawRect? - On iOS, if we use Interface Builder for the UIViewController's view, how do we implement a drawRect for it? iOS:Interface Builder中定义的颜色与Web视图中的颜色不同 - iOS: Colors defined in Interface Builder different from colors in Web View iOS-更改Interface Builder中视图的大小以放入scrollview - iOS - Change size of view in Interface Builder for putting into scrollview 界面构建器视图ui设计在横向模式下更改ios - interface builder view ui design changing in landscape mode ios 基于约束的iOS Update Interface Builder视图框架 - iOS Update Interface Builder view frame based on constraints
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM