简体   繁体   中英

Applying auto layout constraints on custom UIView class Iphone.

I am developing simple iPhone application in which I am using custom UIView class. So when I apply that class to my view in story board it stop accepting my auto layout constraints. I tried to apply constraints in story board. So my custom UIView class looks like

 @implementation RoundedView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    // Initialization code
}
return self;
}
- (void)awakeFromNib
{
[super awakeFromNib];
UIRectCorner corners;
 … some code ...
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
                                               byRoundingCorners:corners
                                                     cornerRadii:CGSizeMake(self.radious, self.radious)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame         = self.bounds;
maskLayer.path          = maskPath.CGPath;
self.layer.mask         = maskLayer;

}

I am applying this class to my view in story board and its working fine but it is not listening for my constraints. So how to apply constraints in this situation. Any one knows about this one? Need some help. Thank you.

You need to change the frame of the layer to match its superview.

- (void)layoutSubviews{
    [super layoutSubviews];
    [maskLayer setFrame:self.bounds];
}

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