简体   繁体   English

UIButton高度限制迅速不起作用

[英]UIButton height constraint swift not working

So I have this UIButton with constraints in a storyboard that looks like this.... with constraints to safe areas as well as a height/width constraint. 因此,我的UIButton在故事板中具有如下约束:...具有安全区域约束以及高度/宽度约束。 the height constraint is set to 30 高度限制设置为30

在此处输入图片说明

but the output looks like... (deff not 30 height and regardless of what I set as the height constraint it looks like the following) also the buttons other than Daily are not shown because they have no constraints yet! 但是输出看起来像...(deff不是30 height,无论我设置为什么高度约束,它看起来都如下图所示),因为没有约束,所以没有显示Daily以外的按钮!

在此处输入图片说明

here are the constraints 这是约束

在此处输入图片说明

在此处输入图片说明

2019-03-04 01:43:35.157418-0500 Daily[831:112538] [LayoutConstraints] Unable to simultaneously satisfy constraints. 2019-03-04 01:43:35.157418-0500 Daily [831:112538] [LayoutConstraints]无法同时满足约束。 Probably at least one of the constraints in the following list is one you don't want. 以下列表中至少有一个约束是您不想要的约束。 Try this: 尝试这个:

(1) look at each constraint and try to figure out which you don't expect; (1)查看每个约束,并尝试找出不期望的约束;

(2) find the code that added the unwanted constraint or constraints and fix it (2)查找添加了一个或多个不必要约束的代码并进行修复

In this case, height and bottom constraint will conflict, I think you have set top, bottom, and height constraint property of UIbutton , So if you want fixed height 15 then remove the bottom constraint. 在这种情况下,高度和底部约束将发生冲突,我认为您已经设置了UIbutton top,bottom和height约束属性,因此,如果您希望将高度固定为15,则可以删除底部约束。 and if you don't want fixed hight then keep as it is a bottom constraint and remove height constraint of UIbutton . 如果不想固定高度,则将其保留为底部约束,并移除UIbutton高度约束。

Look for Constraints error/warning at runtime. 在运行时查找约束错误/警告。 If there is inconsistency, few constraints are removed during runtime. 如果存在不一致,则在运行时将删除很少的约束。

Try setting vertical content hugging property - High. 尝试设置垂直内容拥抱属性-高。 This will inform system, content does not want to grow. 这将通知系统,内容不希望增长。

在此处输入图片说明

Don't use unnecessary constraints as you were set both width and leading, trailing. 在设置宽度和前导,尾随时不要使用不必要的约束。 You can check this by updating constraints as attached image. 您可以通过将约束更新为附加图像来进行检查。

Feel free to ask me if any problem 随时问我是否有问题

*Remember, this is a sample button to guide you. *请记住,这是一个指导您的示例按钮。

在此处输入图片说明

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM