簡體   English   中英

如何在iOS中刪除所選UITabBarItem上的光澤高光?

[英]How to remove the glossy highlight on selected UITabBarItem in iOS?

默認情況下,在UITabbar中,所選的UITabBarItem上有一個亮光突出顯示。

是否可以去除有光澤的高光遮罩?

謝謝。

[[UITabBar appearance] setSelectionIndicatorImage:[[UIImage alloc] init]];

奇跡般有效!

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage {anImage}]]

這會影響您使用的每個選項卡(甚至是子類的)

如果您在此處使用與標簽欄背景顏色相同的圖像,則不會看到指示符。

也許您甚至可以使用完全透明的圖像,或1px * 1px的圖像。

如果要使用自定義圖像自定義選項卡欄項目,則可以這樣做。 我通過將背景圖像添加到繪制了所有選項卡,一個選項卡處於選中狀態而其他選項卡處於未選中狀態的選項卡欄來自定義選項卡欄項。 在每個didSelectViewController中,我更改背景圖像。 然后,我將背景圖像視圖置於最前面,並添加帶有所需標題的自定義標簽。

結果:我自定義了選項卡欄,沒有光澤效果。 有趣的是,UITabBarButtons在背景圖像下,但是仍然可以選擇。

該代碼是這樣的:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    [self customizeTabBar];
}

- (void)customizeTabBar {

    NSString *imageName = [NSString stringWithFormat:@"tabbg%i.png", tabBarCtrl.selectedIndex + 1];

    for(UIView *view in tabBarCtrl.tabBar.subviews) {  
        if([view isKindOfClass:[UIImageView class]]) {  
            [view removeFromSuperview];  
        }  
    }  
    UIImageView *background = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]] autorelease];
    [tabBarCtrl.tabBar insertSubview:background atIndex:0]; 
    [tabBarCtrl.tabBar bringSubviewToFront:background];
        //if needed, here must be adding UILabels with titles, I didn't need it.

}  

也許您會對此感興趣:)

根據Apple的文檔,您可以實現:

(void)setFinishedSelectedImage:
      (UIImage *)selectedImage withFinishedUnselectedImage:
      (UIImage *)unselectedImage

這是一個UITabBar方法

這是鏈接。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM