1. 程式人生 > >iOS開發 view新增陰影

iOS開發 view新增陰影

建立控制元件

        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(WIDTH/2-85, self.frame.size.height-15, 170, 30)];

        view.hidden = YES;

        view.backgroundColor = [UIColor whiteColor];

        view.clipsToBounds = YES;

        view.layer.cornerRadius = 5;

        [self addSubview:view];

新增陰影

        UIBezierPath *shadowPath = [UIBezierPath

                                    bezierPathWithRect:view.bounds];

        view.layer.masksToBounds = NO;

        view.layer.shadowColor = [UIColor lightGrayColor].CGColor;

        view.layer.shadowOffset = CGSizeMake(0.0f, 1.0f);

        view.layer.shadowOpacity = 0.5f;

        view.layer.shadowPath = shadowPath.CGPath;