Swift:为iPad屏幕调整NavigationBar的大小

时间:2018-05-04 06:08:09

标签: ios swift uinavigationcontroller uinavigationbar

我有一个导航栏,在iphone设备上看起来很完美,但在iPad上打开它看起来非常小。我正在使用故事板进行设计,如何调整导航栏的大小和ipad的字体。

enter image description here

1 个答案:

答案 0 :(得分:0)

导航栏的高度固定为65,状态栏。 但是如果你想改变导航条的高度,你可以采取以下替代方式。

let height: CGFloat = 50 //whatever height you want to add to the existing height
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)

并设置字体。

if (UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad)
        {
            UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName :NavigationColor,
                                                                NSFontAttributeName: FontLight_40
            ]
            UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName:FontLight_40], for: UIControlState.normal)
        }
        else
        {
            UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName :NavigationColor,
                                                                NSFontAttributeName: FontLight_20
            ]
            UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName:FontLight_20], for: UIControlState.normal)
        }