[英]iOS UITabBar : Remove top shadow gradient line
我實現了一個自定義 UITabBar 並且我仍然在它上面有這個漸變/陰影。 我加了
[self.tabBar setBackgroundImage:[UIImage imageNamed:@"navBarBottom.png"]];
這只是改變背景但保持陰影漸變。
我究竟做錯了什么 ? 有什么要指定的來擺脫它嗎?
我擁有的 :
我想要的是 :
謝謝你。
類似地回答這個問題......如果你不想弄亂任何類型的 1x1 透明圖像,這項工作也是:
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
迅速:
UITabBar.appearance().shadowImage = UIImage()
UITabBar.appearance().backgroundImage = UIImage()
嘗試為 UITabBar 設置一個 1x1 像素的透明陰影圖像:
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparentShadow.png"]];
迅速
為您的自定義標簽欄試試這個。 它將隱藏水平陰影線。
self.tabBar.setValue(true, forKey: "_hidesShadow")
目標 C
[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];
斯威夫特 4
UITabBar.appearance().layer.borderWidth = 0.0
UITabBar.appearance().clipsToBounds = true
此代碼適用於 iOS 13 及更低版本
if #available(iOS 13, *) {
let appearance = self.tabBar.standardAppearance.copy()
appearance.backgroundImage = UIImage()
appearance.shadowImage = UIImage()
appearance.shadowColor = .clear
self.tabBar.standardAppearance = appearance
} else {
self.tabBar.backgroundImage = UIImage()
self.tabBar.shadowImage = UIImage()
}
調用[[UITabBar appearance] setShadowImage:]
將自定義您應用中的所有UITabBar
實例。
如果你只想自定義一個UITTabBar
,你可以這樣做:
[self.tabBarController.navigationController.navigationBar setShadowImage:[UIImage new]];
這是另一個易於實施的答案:
[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];
為我工作。
只是設置圖像它不會刪除你必須將其邊框寬度設置為 0 的陰影線。這是代碼
[[UITabBar 外觀] setShadowImage:[UIImage new]];
[UITabBar 外觀].layer.borderWidth = 0.0f;
[UITabBar 外觀].clipsToBounds = true;
把它放在你的AppDelegate下didFinishLaunchingWithOptions :
[[UITabBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];
試試這個,** Objective-C **
//Remove shadow image by assigning nil value.
[[UITabBar appearance] setShadowImage: nil];
// or
// Assing UIImage instance without image reference
[[UITabBar appearance] setShadowImage: [[UIImage alloc] init]];
** 斯威夫特 **
//Remove shadow image by assigning nil value.
UITabBar.appearance().shadowImage = nil
// or
// Assing UIImage instance without image reference
UITabBar.appearance().shadowImage = UIImage()
這是shadowImage 的蘋果指南。
@available(iOS 6.0, *)
open var shadowImage: UIImage?
默認為零。 當非零時,顯示自定義陰影圖像而不是默認陰影圖像。 要顯示自定義陰影,還必須使用 -setBackgroundImage: 設置自定義背景圖像(如果使用默認背景圖像,則將使用默認陰影圖像)。
我通過以下方法獲得了相同的外觀。
1. 將背景欄色調顏色設置為與主父視圖背景顏色相同。
2.
this.TabBar.BarStyle = UIBarStyle.BlackOpaque;
我在 Xamarin 中使用過,請驗證 Swift 語法。
如果您需要從具有自定義字體的選項卡欄中刪除 iOS 13 上的陰影線,則必須以這種方式應用它:
if #available(iOS 13.0, *) {
let appearance = UITabBarAppearance()
appearance.stackedLayoutAppearance.normal.titleTextAttributes = ...
appearance.stackedLayoutAppearance.selected.titleTextAttributes = ...
appearance.shadowColor = .clear
tabBar.standardAppearance = appearance
}
在大多數視圖控制器在 viewDidLoad 中繼承的視圖控制器或視圖控制器或 BasicViewController 中,只需放置以下兩行:
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tab_bar_background"]];
[[UITabBar appearance] setShadowImage:[UIImage imageNamed:@"transparent_shadow"]];
確保 transparent_shadow@2x.png 是 1x1 或 2x2 透明的圖像,tab_bar_background@2x.png 是 640x100 的圖像,因為底部欄的高度為 50 像素。
適用於 iOS 9.3
在 viewDidload 上試試這個。
override func viewDidLoad() {
super.viewDidLoad()
self.tabBar.setValue(true, forKey: "_hidesShadow")
}
它對我有用
在 iOS 7 中 - 這有效:
[self.actionToolbar setShadowImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny];
[self.actionToolbar setBackgroundImage:[[UIImage alloc] init] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
希望能幫助某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.