UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(100, 100, 100, 44)];
btn.backgroundColor = [UIColor redColor];
btn.titleLabel.textColor = [UIColor whiteColor];
[btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[btn setTitle:@"保存到相册" forState:UIControlStateNormal];
btn.layer.cornerRadius = 22;
btn.layer.shadowPath = [UIBezierPath bezierPathWithRect:btn.bounds].CGPath;//阴影的位置
btn.layer.shadowColor = [UIColor orangeColor].CGColor;//阴影颜色
btn.layer.shadowOffset = CGSizeMake(0, 10);//阴影的大小,x往右和y往下是正
btn.layer.shadowRadius = 5; //阴影的扩散范围,相当于blur radius,也是shadow的渐变距离,从外围开始,往里渐变shadowRadius距离
btn.layer.shadowOpacity = 1; //阴影的不透明度
btn.layer.masksToBounds = NO; //很重要的属性,可以用此属性来防止子元素大小溢出父元素,如若防止溢出,请设为 true
[self.view addSubview:btn];
网友评论