在iOS 7中更改UIToolbar的高度 [英] Changing the height of UIToolbar in iOS 7

查看:252
本文介绍了在iOS 7中更改UIToolbar的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在新的iOS 7项目中更改我的UIToolbar的高度,但我无法。

I am trying to change the height of my UIToolbar in a new iOS 7 project but I am not able to.

我正在使用UINavigationController来管理一对UIViewController。
我尝试通过导航控制器设置工具栏的框架但是,工具栏属性是只读的。

I am using a UINavigationController to manage a couple of UIViewController. I tried setting the frame for the toolbar via the navigation controller but alas, the toolbar property is read-only.

我看了有没有办法改变UIToolbar的高度?但是没有用。

我尝试了UIToolbar的子类化,强制自定义高度并在Storyboard中设置正确的类但是这两个都不起作用,高度保持是44px。

I tried subclassing UIToolbar, forcing a custom height and setting the right class in the Storyboard but that did not work neither, height keeps on being 44px.

我认为自动布局无法对工具栏的大小设置任何限制,每个字段都被禁用。

I thought about auto-layout could not set any constraint on the size of the toolbar, every field is disabled.

我可以在UIBarButtonItem中设置一个比工具栏更高的自定义视图。大项目将被正确呈现,但它将从工具栏中溢出。

I can set a custom view in a UIBarButtonItem with a bigger height than the toolbar. The big item will be correctly rendered but it will overflow from the toolbar.

这是我能做的最好的:屏幕截图

This is the best I could do: screenshot

实际上是否可以更改UIToolbar的高度IOS 7?
或者我应该创建一组自定义项来模仿它?

Is it actually possible to change the height of the UIToolbar in iOS 7? Or am I supposed to create a bunch of custom items to mimic it?

推荐答案

遵循@Antoine建议使用 sizeThatFits ,这是我的工具栏子类,高度为64:

Following the @Antoine suggestion using sizeThatFits, here is my Toolbar subclass with an height of 64:

import UIKit

class Toolbar: UIToolbar {
    override func layoutSubviews() {
        super.layoutSubviews()
        frame.size.height = 64
    }

    override func sizeThatFits(size: CGSize) -> CGSize {
        var size = super.sizeThatFits(size)
        size.height = 64
        return size
    }
}

然后,在初始化导航控制器时,我说应该使用该类:

Then, when initializing the navigation controller, I say it should use that class:

let navigationController = UINavigationController(navigationBarClass: nil, toolbarClass: Toolbar.self)

这篇关于在iOS 7中更改UIToolbar的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆