如何使用Swift更改按钮的高度? [英] How can I change the height of a button with Swift?

查看:92
本文介绍了如何使用Swift更改按钮的高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据屏幕的高度,我想调整视图中按钮的高度.在Swift中最简单的方法是什么?

Depending on the height of the screen, I would like to adjust the height of a button in a view. What is the easiest way to do this in Swift?

我以这种方式以及CGRectMake()进行了尝试,但没有任何变化:

I tried it in this way and also with CGRectMake() but nothing changed:

self.myButton.frame.size.height = self.myButton.frame.size.height*scrOpt

如何更新"框架?

推荐答案

未看到任何更改的原因可能是因为您使用的是AutoLayout,并且该按钮已应用了一些约束,因此您需要更改高度完成您想要的约束.

The reason why you see no changes may be because you're using AutoLayout, and the button has some constraints applied to it, and you need to change the height constraint to accomplish what you want.

已编辑:在Swift中似乎可以直接更改框架属性,但在Objective C中则无法.

Edited: Changing frame properties directly seems to be possible in Swift but was not possible in Objective C.

这篇关于如何使用Swift更改按钮的高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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