如何摆脱右侧阴影但保持按钮上的底部阴影

时间:2018-03-13 06:39:53

标签: ios objective-c uibutton shadow

我有循环创建一行按钮,我有以下代码来设置阴影。如何摆脱右侧阴影但保持底部阴影?

    button.imageView.layer.cornerRadius = 7.0f;
    button.layer.shadowRadius = 1.0f;
    button.layer.shadowColor = [UIColor blackColor].CGColor;
    button.layer.shadowOffset = CGSizeMake(0.0f, 2.0f);
    button.layer.shadowOpacity = 0.5f;
    button.layer.masksToBounds = NO;

Pic

1 个答案:

答案 0 :(得分:0)

答案

正如建议添加的UIView

navigationView = [[UIView alloc]initWithFrame:CGRectMake(X_BUFFER+5,Y_POS_BTN,self.view.frame.size.width-10,HEIGHT_BTN)];
navigationView.backgroundColor = [UIColor whiteColor];

[self.view addSubview:navigationView];

UIBezierPath *shadowPath = [UIBezierPath bezierPathWithRect:self.navigationView.bounds];
self.navigationView.layer.masksToBounds = NO;
self.navigationView.layer.shadowColor = [UIColor blackColor].CGColor;
self.navigationView.layer.shadowOffset = CGSizeMake(5.0f, 5.0f);
self.navigationView.layer.shadowOpacity = 0.8f;
self.navigationView.layer.shadowPath = shadowPath.CGPath;
相关问题