Skip to content

Instantly share code, notes, and snippets.

@Zumbalamambo
Forked from gelldur/CardView.h
Created May 5, 2017 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zumbalamambo/54acbc353046f363c197c3bd5c05f86b to your computer and use it in GitHub Desktop.
Save Zumbalamambo/54acbc353046f363c197c3bd5c05f86b 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