如何在iOS 11中设置UIBarButton大小以匹配iOS 10中的大小 [英] How to set UIBarButton size in iOS 11 to match size in iOS 10

查看:64
本文介绍了如何在iOS 11中设置UIBarButton大小以匹配iOS 10中的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图控制器,其中带有一个简单的UINavigationBar和一个rightBarButtonItem,其中包含带有图像资产的按钮视图.

I have an view controller with a simple UINavigationBar with a rightBarButtonItem which contains a button view with an image asset.

在iOS 10中,此UIBarButtonItem的大小将适当调整,不会填满整个高度和导航栏,因此会占用足够的宽度以与高度成比例.类似于UIBarButton项在整个iOS的Apple应用程序中的外观.

In iOS 10, this UIBarButtonItem would be sized properly, not filling up the entire height and of the navigation bar and therefore taking up enough width to stay proportional to the height. Similar to how UIBarButton items look in Apple's app throughout iOS.

现在,在iOS 11中,这些图标非常庞大,并且比iOS 10中占用的空间更多.

Now in iOS 11, these icons are massive and take up way more space than they used to in iOS 10.

有没有办法将它们恢复到在iOS 10上的外观?我尝试将约束添加到UIBarButtonItems的customView属性无济于事.

Is there a way to restore them to how they looked on iOS 10? I tried adding constraints to the customView property of the UIBarButtonItems to no avail.

推荐答案

您的方法是正确的:自定义条形按钮项目现在可以自动布局,因此您必须添加约束来设置大小.这是一个非常需要的功能,所以不用担心,要开心!

Your approach is correct: custom bar button items now do autolayout, so you must add constraints to set the size. This is a much-requested feature, so don't worry, be happy!

您必须添加的约束类似于表格单元格高度的约束:您必须添加足够的约束以从内向外完全调整条形按钮项目的自定义视图完全的大小.例如,为其提供绝对宽度和高度约束,或者为其内容提供宽度和高度约束以及将其固定到自定义视图本身边界的约束.

The constraints you must add are like the constraints for a table cell height: you must add sufficient constraints to size the bar button item's custom view completely from the inside out. For example, give it absolute width and height constraints, or give its contents width and height constraints plus constraints pinning them to the boundaries of the custom view itself.

这篇关于如何在iOS 11中设置UIBarButton大小以匹配iOS 10中的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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