iOS:如何给`tabbar` 添加阴影?

标签 ios shadow tabbar

我有一个测试,可以将阴影添加到我的 tabbar,但它没有用。我的代码如下:

    _button.layer.shadowColor = [UIColor grayColor].CGColor;
    _button.layer.shadowOffset = CGSizeMake(4,4);
    _button.layer.shadowOpacity = 0.8;
    _button.layer.shadowRadius = 4;

    /* remove tab-line */
    [[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
    [self.tabBarController.tabBar setClipsToBounds:YES];

    self.tabBarController.tabBar.layer.shadowColor = [UIColor grayColor].CGColor;
    self.tabBarController.tabBar.layer.shadowOffset = CGSizeMake(0,-4);
    self.tabBarController.tabBar.layer.shadowOpacity = 0.8;
   self.tabBarController.tabBar.layer.shadowRadius = 4;

我还拍了一张照片来证明:

the button has shadow but tabbar has nothing

最佳答案

创建带有阴影的图像,然后按如下方式使用。

[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] INITWITHYOURCUSTOMIMAGE]]; 
[[UITabBar appearance] setShadowImage:[[UIImage alloc] INITWITHYOURCUSTOMIMAGE]];

迅速:

UITabBar.appearance().shadowImage = UIImage(named:"YOURIMAGE")
UITabBar.appearance().backgroundImage = UIImage(named:"YOURIMAGE")

关于iOS:如何给`tabbar` 添加阴影?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38045282/

相关文章:

java - 在 gwt 中更 retrofit 饰标签栏的背景图像

ios - 如何识别哪个 GMSMarker 被点击 - iOS, Swift

ios - UITextView 上的 NSRegularExpressions 性能

windows - 自定义鼠标光标的阴影 (2)

css - 具有流体高度的 PNG 阴影

tabbar - 滚动到底部后iOS 15标签栏透明

ios - 如何知道点击了哪个 Tabbar 菜单

ios - Nib 内的 UISwitch 值未更新

ios - 核心数据 swift : Crash : SQLite error code:14, 'unable to open database file'

html - 将阴影与背景滤镜一起使用 : blur