以编程方式创建具有默认高度的 UIToolbar [英] Programmatically create UIToolbar with default height

查看:25
本文介绍了以编程方式创建具有默认高度的 UIToolbar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于UIToolbar的高度有很多问题,但是我没有看到动态获取高度的问题.有没有办法用正确的默认高度创建 UIToolbar ?

There are a number of questions regarding the height of UIToolbar, but I don't see one where the height is obtained dynamically. Is there a way to create a UIToolbar with the correct default height?

推荐答案

创建高度为 0 的工具栏,然后调用 sizeToFit.工具栏将具有默认高度.

Create the toolbar with 0 height, then call sizeToFit. The toolbar will then have the default height.

UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, width, 0)];
[toolbar sizeToFit];

Swift 版本:

let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: width, height: 0))
toolbar.sizeToFit()

这篇关于以编程方式创建具有默认高度的 UIToolbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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