How to get the height of the tabbar programmatically?

前端 未结 7 661
遥遥无期
遥遥无期 2021-01-31 13:53

I\'ve found out that the height of a UITabBar is 49px (or 50px, depending on the source).

Because I don\'t like to use too much hard-coded values in my code I was wonder

相关标签:
7条回答
  • 2021-01-31 14:22

    In Swift 3, you can retrieve the height of the UITabBar with this code below.

    self.tabBarController!.tabBar.frame.size.height

    Which will return a CGFloat value of the height

    0 讨论(0)
  • 2021-01-31 14:23

    UITabBar is inherited from UIView as long as you mhave access to your UITabBar instance you can access and modify the frame of UITabBar,

    CGRect myRect = myTabBar.frame;
    
    0 讨论(0)
  • 2021-01-31 14:25

    If you want to get the standard height for the UITabBar control then you can do:

        UITabBarController *tabBarController = [UITabBarController new];
        CGFloat tabBarHeight = tabBarController.tabBar.frame.size.height;
    
    0 讨论(0)
  • 2021-01-31 14:29

    prettier

    CGRectGetHeight(self.tabBarController.tabBar.frame)
    
    0 讨论(0)
  • 2021-01-31 14:33

    I don't totally understand your P.S., but you can do:

    tabBarController?.tabBar.frame.size.height
    
    0 讨论(0)
  • 2021-01-31 14:43

    If an object is based on UIView (which most visual elements in the library are), you can get the size from the ivar "frame".

    0 讨论(0)
提交回复
热议问题