如何向UINavigationController添加阴影 [英] How to add shadow to UINavigationController

查看:128
本文介绍了如何向UINavigationController添加阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在路径或Facebook中创建一个幻灯片菜单,在我的菜单和UINavigationController之间有一个阴影,其中包含所有内容。我可以为图层添加圆角,但不会显示我应用于图层的阴影。这段代码有什么问题?如果我使用UIViewController而不是UINavigationController ...(代码在作为rootViewController添加到UINavigationController的视图中),它正在工作。

I want to create a Slide Menu like in Path or Facebook with a shadow between my menu and the UINavigationController with all the content inside. I can add rounded corners to the layer but the shadow I apply to the layer is not shown. What is wrong with that code? It is working if I use a UIViewController instead of the UINavigationController... (The code is inside a view added as rootViewController to the UINavigationController)

问题是我不知道我想要松开UINavigationController的圆形边框

The problem is that I don't want to loose the rounded borders of the UINavigationController

self.navigationController.view.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.navigationController.view.bounds cornerRadius:self.navigationController.view.layer.cornerRadius].CGPath;
[self.navigationController.view.layer setMasksToBounds:YES];
[self.navigationController.view.layer setShadowColor:[UIColor blackColor].CGColor];
[self.navigationController.view.layer setShadowOffset:CGSizeMake(0, 0)];
[self.navigationController.view.layer setShadowOpacity:0.5];
[self.navigationController.view.layer setShadowRadius:3];
[self.navigationController.view.layer setCornerRadius:3];


推荐答案

在Swift3中

self.navigationController?.view.layer.shadowOffset = CGSize(width: 0, height: 5)
self.navigationController?.view.layer.masksToBounds = true

这篇关于如何向UINavigationController添加阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆