@interface GC_Demo_Controller ()
@property(nonatomic, strong) CALayer *gc_layer;
@property(nonatomic, strong) Basic_Button *button;
@end
@implementation GC_Demo_Controller
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"";
self.navigationItem.rightBarButtonItems = @[];
// 创建阴影层级
CALayer *layer = [CALayer layer];
// 这个必须设置
layer.backgroundColor = HEX_RGB(0x000000).CGColor;
// 阴影颜色
layer.shadowColor = HEX_RGB(0x99aabb).CGColor;
// 阴影偏移程度
layer.shadowOffset = CGSizeMake(5, 5);
// 阴影的透明度
layer.shadowOpacity = 0.5;
_gc_layer = layer;
// 添加层级
[self.view.layer addSublayer:layer];
// 给按钮添加阴影就得将按钮添加到阴影之上
Basic_Button *button = [[Basic_Button alloc] init];
[self.view addSubview:button];
// 设置按钮背景图片
UIImage *gc_Image = GC_C_Image(HEX_RGB(0x234567));
[button setBgImage:gc_Image forState:UIControlStateNormal];
_button = button;
}
- (void)viewWillLayoutSubviews {
[super viewWillLayoutSubviews];
_gc_layer.frame = CGRectMake(100, 200, 200, 30);
_button.frame = _gc_layer.frame;
// 阴影圆角
_gc_layer.cornerRadius = 15;
CHViewBorderRadius(_button, _button.height / 2, 0, Clear_Color);
}