2013-06-28 31 views
8

Tôi đã tạo một tabBar và đặt hình ảnh trong đó, nhưng nó để lại quá nhiều không gian bên dưới tabBarItem. Làm thế nào tôi có thể loại bỏ điều đó?Làm cách nào để xóa không gian bên dưới UITabBarItem?

Đây là tabBar tôi hơn hiển thị ngay bây giờ

enter image description here

Và tôi muốn hiển thị nó như thế này

enter image description here

Để hiển thị thanh tabbar

firstVC = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
secondVC = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 
thirdVC = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil]; 
forthVC = [[ForthViewController alloc] initWithNibName:@"ForthViewController" bundle:nil]; 

    [[UITabBar appearance] setTintColor:[UIColor whiteColor]]; 

    NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:firstVC,secondVC,thirdVC,forthVC, nil]; 

    self.tabController = [[UITabBarController alloc] init]; 
    [self.tabController setViewControllers:viewControllersArray animated:NO]; 


    [self.window addSubview:self.tabController.view]; 

    //self.tabController.selectedIndex = 1; 

    self.tabController.delegate = self; 

    self.window.rootViewController = self.tabController; 
    [self.window makeKeyAndVisible]; 

Đối với hình nền TabBar tôi đã sử dụng mã này

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

Và đối với thiết lập imge tại mục tôi đã sử dụng mã này

//used to set the tabBarItem images 
     [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"home_tab"] withFinishedUnselectedImage:[UIImage imageNamed:@"home_tab"]]; 
     //Set the badge on tabBarItem 
     [self.tabBarItem setBadgeValue:@"15"]; 
+0

thanh tabbar của bạn ở đâu? như bạn đã viết "Đây là thanh tabbar của tôi hơn hiển thị ngay bây giờ" –

+0

Có vấn đề gì khi tôi thêm hình ảnh của mình trong câu hỏi nó hiển thị một số hình ảnh khác như hình ảnh thành phố GTA .... Lạ .... –

+0

Hey @Kane Don Không hiển thị thanh tab của bạn ...... –

Trả lời

17

Như Vytis nói trong their answer here:

Có một thuộc tính trên UIBarItem (mục UIBarButton kế thừa từ lớp này ) imageInsets.

Để sử dụng hình ảnh chiều cao đầy đủ (49px) cho finishedSelectedImagefinishedUnselectedImage bạn cần phải thiết lập các insets ảnh:

tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

bạn phải viết những dòng sau mã

item0.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 
item1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 
item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 
item2.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0); 
+1

Khi bạn sao chép các từ của một từ khác, bạn cần gọi một cách rõ ràng và liên kết với câu trả lời gốc. Tôi đã làm như vậy ở trên, nhưng hãy đảm bảo rằng bạn cung cấp phân bổ phù hợp trong tương lai. –

+0

Câu trả lời hay đấy +1 .. –

9

I nghĩ rằng bạn nên sử dụng côn trùng hình ảnh trong xib cho điều này như, enter image description here

cho yêu cầu của bạn trên cùng phải là một số giá trị dương và đáy phải có cùng giá trị âm. Nếu bạn đã thêm thanh tab lập trình thì bạn có thể tham khảo Wills để trả lời

+0

Tôi nghĩ cách này tốt hơn b/c bạn có thể chỉnh sửa nó trên trình tạo giao diện, btw nó vẫn hoạt động trên xcode 7 – norman784

Các vấn đề liên quan