How to create UINavigationBar drop shadow

后端 未结 4 1741
臣服心动
臣服心动 2020-12-22 21:09

Would like to know create drop shadow for UINavigationbar. I tried to create custom navigation bar background with drop shadow, but the drop shadow cover the background view

4条回答
  •  情歌与酒
    2020-12-22 21:57

    I stick the shadow drawing code into a function to keep loadView clean. You could pass in the object you want to draw the shadow on if you wanted all your shadows consistent.

    - (void)loadView
    {
        self.view = [[UIView alloc] init];
        self.view.backgroundColor = [UIColor whiteColor];
    
        [self drawShadow];
    }
    
    
    - (void)drawShadow
    {
        self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
        self.navigationController.navigationBar.layer.shadowOpacity = 0.3;
        self.navigationController.navigationBar.layer.shadowOffset = CGSizeMake(0, 0);
        self.navigationController.navigationBar.layer.shadowRadius = 15;
        self.navigationController.navigationBar.layer.masksToBounds = NO;
    }
    

提交回复
热议问题