如何使sizeToFit忽略宽度? [英] How to make sizeToFit ignore width?

查看:108
本文介绍了如何使sizeToFit忽略宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一段代码中使用sizeToFit,我希望它忽略宽度,但只是根据高度适合大小。这可能吗?

I am using sizeToFit in a piece of code where I want it to ignore the width but just "size to fit" based on height. Is that possible?

推荐答案

您可以存储原始边界,并在调用<$后将新边界设置为旧宽度c $ c> -sizeToFit 。

You could store the original bounds, and set the new bounds to have the old width after calling -sizeToFit.

CGRect oldBounds = someView.bounds;
[someView sizeToFit];
CGRect newBounds = someView.bounds;
newBounds.size.width = oldBounds.size.width;
someView.bounds = newBounds;

这篇关于如何使sizeToFit忽略宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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