簡體   English   中英

帶大圖標的選項卡欄

[英]Tab Bar with Large Icons

我想知道是否有一種方法可以僅使用大圖標來完成選項卡欄,我在下面附加了圖像以供參考。 我對創建自己的標簽欄控制器以及自己管理視圖控制器不感興趣。

在此處輸入圖片說明

這是我的解決方案,我創建了一個類,它是UITabBarController的子類。

CustomTabBarController.h

@interface CustomTabBarController : UITabBarController<UITabBarControllerDelegate>
@property (strong, nonatomic) IBOutlet UITabBar *tabBar;
@end

CustomTabBarController.m

- (void)viewDidLoad
{
    CGRect tabBarFrame = self.tabBar.frame ;
    tabBarFrame.origin.y -= kOrigin;
    tabBarFrame.size.height = kTabBarHeight;
    self.tabBar.frame = tabBarFrame;
    self.tabBarController.delegate = self;
    /* Tab Bar Background */

    UIImage *tabBarBackgroundImage = [UIImage imageNamed:@"tabBarBackgroundImage.png"];
    [[UITabBar appearance] setBackgroundImage:tabBarBackgroundImage];

    /* Tab Bar Item */
    UIButton *surveyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [surveyButton addTarget:self action:@selector(surveyButtonDidSelect) forControlEvents:UIControlEventTouchUpInside];
    surveyButton.tag = surveyButtonTag;
    [surveyButton setBackgroundImage:[UIImage imageNamed:@"someimage.png"] forState:UIControlStateNormal];
    CGRect surveyButtonFrame = surveyButton.frame ;
    surveyButtonFrame.origin.x = /*Proper value in your case */;
    surveyButtonFrame.origin.y = /*Proper value in your case */;
    surveyButtonFrame.size.height = /*Proper value in your case */ ;
    surveyButtonFrame.size.width =/*Proper value in your case */;
    surveyButton.frame = surveyButtonFrame;
    [self.tabBar addSubview:surveyButton];

    UIButton *statusButton = [UIButton buttonWithType:UIButtonTypeCustom];
    statusButton.tag = statusButtonTag;
    [statusButton addTarget:self action:@selector(statusButtonDidSelect) forControlEvents:UIControlEventTouchUpInside];
    [statusButton setBackgroundImage:[UIImage imageNamed:@"someimage.png"] forState:UIControlStateNormal];
    CGRect statusButtonFrame = statusButton.frame ;
    statusButtonFrame.origin.x = /*Proper value in your case */;
    statusButtonFrame.origin.y = /*Proper value in your case */;
    statusButtonFrame.size.height = /*Proper value in your case */;
    statusButtonFrame.size.width = /*Proper value in your case */;
    statusButton.frame = statusButtonFrame;
    [self.tabBar addSubview:statusButton];
}

-(void)surveyButtonDidSelect
{
    self.selectedIndex = 0 ;
}
-(void)statusButtonDidSelect
{
    self.selectedIndex = 1;
}

它為我工作,我沒問題。 希望能幫助到你。

要添加到@limon的答案中,如果您想更改自定義UITabBar的高度,我從另一個SO答案中找到了,抱歉,不記得Web鏈接參考了,下面的代碼起到了作用並將其鎖定在底部,在哪里我用@limon的代碼發現UITabBar的位置與他的代碼不在盒子底部齊平:

override func viewWillLayoutSubviews() {
    //UITabBar Height
    var tabFrame: CGRect = self.tabBar.frame
    tabFrame.size.height = 75
    tabFrame.origin.y = self.view.frame.size.height - 75
    self.tabBar.frame = tabFrame
}

顯然,您想從limon的答案中刪除類似的代碼,或者也許將其整個代碼段移至viewWillLayoutSubviews我沒有嘗試過,我在viewDidLoad調用了他的代碼

iPhone 5 / iPhone 4的選項卡欄中圖像的最大尺寸為96 x 64,因此您在此處有限度而不會自行滾動。 盡管在您的示例圖像中,這些可能適合約束。

暫無
暫無

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

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