gpt4 book ai didi

ios - 如何为UINavigation栏添加阴影效果

转载 作者:技术小花猫 更新时间:2023-10-29 11:11:13 27 4
gpt4 key购买 nike

enter image description here

你好,我想为我的 NAvigationBar 添加这种阴影,我该怎么做。

这就是我尝试添加阴影的方式。

[self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.shadowImage=[UIImage new];

self.navigationController.navigationBar.translucent=YES;

self.navigationController.navigationBar.topItem.titleView.tintColor=[UIColor whiteColor];
self.navigationController.navigationBar.titleTextAttributes=[NSDictionary dictionaryWithObject:[UIFont fontWithName:@"HelveticaNeue" size:15.0f] forKey:NSFontAttributeName];
self.navigationController.navigationBar.topItem.title=strNavigtionTitle;
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"backarrow"] style:UIBarButtonItemStylePlain target:self action:@selector(revealToggle :)];
[self.navigationController navigationBar].tintColor = [UIColor whiteColor];

[self.navigationController navigationBar].layer.shadowColor=[UIColor colorWithRed:53.0/255.0 green:108.0/255.0 blue:130.0/255.0 alpha:1.0f].CGColor;
[self.navigationController navigationBar].layer.shadowOffset=CGSizeMake(0, 20);
[self.navigationController navigationBar].layer.shadowOpacity=0.8;
[self.navigationController navigationBar].layer.shadowRadius=5.5;

但这只会为箭头和我的申请休假标题添加阴影。但是我想像这张图片一样添加阴影。它应该在 NavigationBar 和我的主要 UIView 之间 我该怎么做?请帮我。谢谢

最佳答案

在这里您需要导入 QuartzCore 框架。

self.navigationController.navigationBar.layer.borderColor = [[UIColor whiteColor] CGColor];
self.navigationController.navigationBar.layer.borderWidth = 2; //Set border you can see the shadow
self.navigationController.navigationBar.layer.shadowColor = [[UIColor blackColor] CGColor];
self.navigationController.navigationBar.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
self.navigationController.navigationBar.layer.shadowRadius = 3.0f;
self.navigationController.navigationBar.layer.shadowOpacity = 1.0f;
self.navigationController.navigationBar.layer.masksToBounds = NO;

还有一点你必须

set self.layer.masksToBounds = NO;

此属性的默认值为 YES,这意味着即使渲染了阴影,它也不会在 View 边界之外渲染,这实际上意味着您根本看不到它。

如果您以任何方式为这个 View 设置动画,您还应该添加这一行:

self.layer.shouldRasterize = YES;

关于ios - 如何为UINavigation栏添加阴影效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34152221/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com