Skip to content

Instantly share code, notes, and snippets.

@gelldur
Last active July 11, 2019 13:14
Show Gist options
  • Save gelldur/8e9d2586478eb9319ec5d9f21b517aa4 to your computer and use it in GitHub Desktop.
Save gelldur/8e9d2586478eb9319ec5d9f21b517aa4 to your computer and use it in GitHub Desktop.
iOS view that looks like CardView from Android
#import <UIKit/UIKit.h>
//Based on: https://github.com/aclissold/CardView
@interface CardView : UIView
@end
#import "CardView.h"
@implementation CardView
- (void)layoutSubviews
{
[super layoutSubviews];
float cornerRadius = 2;
int shadowOffsetWidth = 0;
int shadowOffsetHeight = 3;
float shadowOpacity = 0.5;
UIColor* shadowColor = [UIColor blackColor];
UIBezierPath* shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:cornerRadius];
self.backgroundColor = [UIColor blueColor]; // TODO change color
self.layer.cornerRadius = cornerRadius;
self.layer.masksToBounds = false;
self.layer.shadowColor = shadowColor.CGColor;
self.layer.shadowOffset = CGSizeMake(shadowOffsetWidth, shadowOffsetHeight);
self.layer.shadowOpacity = shadowOpacity;
self.layer.shadowPath = shadowPath.CGPath;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment