I have 2 subselects in a cell. One for the shadow view and the other for the corner radius, as it sounds pretty good what I found from this link . So I tried to do this in Objective-C using IBDessignables. Everything works fine if the cell is the same size, but for a shadow of dynamic size it is displayed above another cell, but the cornerview is fine.
- view cell hierarchy -
Here is my code for shadow representation
ShadowView.h
IB_DESIGNABLE
@interface ShadowView : UIView
@property (nonatomic) IBInspectable CGFloat cornerRadius;
@property (nonatomic) IBInspectable CGFloat shadowRadius;
@property (nonatomic) IBInspectable CGSize shadowOffset;
@end
ShadowView.m
@implementation ShadowView
-(void)setup{
self.cornerRadius = 5.0f;
self.shadowRadius = 2.0f;
self.shadowOffset = CGSizeMake(0, 0);
self.backgroundColor = [UIColor clearColor];
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}
- (void)drawRect:(CGRect)rect {
[self updateLayerProperties];
}
- (void)updateLayerProperties {
self.layer.shadowOffset = self.shadowOffset;
self.layer.shadowRadius = self.shadowRadius;
self.layer.shadowOpacity = 0.3;
self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.cornerRadius].CGPath;
self.layer.masksToBounds = NO;
self.layer.shouldRasterize = YES;
self.layer.rasterizationScale = [UIScreen mainScreen].scale;
}
@end
So does anyone know what the exact problem is? Because the angles of the angle of view work fine, but not the shadow representation.
Demo file
, - . https://www.dropbox.com/s/myxjyj5pu3ey3aw/demoDesignables.zip?dl=0