简体   繁体   中英

IOS use inherited View inside interface builder

I've extended UIImageView inorder to create a rounder image view:

#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.

故事板

How can i make it work that whenever i attach an custom view to my UIView, the custom view will be initialised ?

Override this initializer when creating views from storyboard:

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder: aDecoder];

    if (self) {
        [self makeImageViewRounded];
    }

    return self;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM