- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的应用中有两个按钮具有相同的宽度限制。
我需要隐藏右侧按钮并调整左侧按钮的大小以适应屏幕的整个宽度。
我尝试了以下方法(均无效):
隐藏右键,去掉等宽约束以编程方式,然后调整左侧按钮框架的大小,最后,调用 setNeedsUpdateConstraints
。完整代码如下:
self.btnRight.hidden = YES;
[self.view removeConstraint:_btnWidthEqualConstraint];
CGRect buttonFrame = self.btnLeft.frame;
buttonFrame.size = CGSizeMake(300, 70);
self.btnLeft.frame = buttonFrame;
[self.btnLeft setNeedsUpdateConstraints];
更新约束:
UIScreen *screen = [UIScreen mainScreen];
CGRect screenSize = screen.bounds;
self.btnRight.hidden = YES;
[self.btnRight updateConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@(0));
}];
[self.btnLeft updateConstraints:^(MASConstraintMaker *make) {
make.width.equalTo(@(screenSize.size.width-12));
}];
如何隐藏右侧按钮并调整左侧按钮的大小以适应屏幕的整个宽度?
最佳答案
使用具有以下设置的 UIStackView
:
let leftButton = UIButton(type: .system)
let rightButton = UIButton(type: .system)
let stackView = UIStackView(arrangedSubviews: [leftButton, rightButton])
stackView.axis = .horizontal
stackView.alignment = .fill
stackView.distribution = .fillEqually
stackView.spacing = 8 // or whatever spacing you wish to have between the buttons
然后您可以简单地隐藏一个按钮 (leftButton.isHidden = true
),而另一个占据整个宽度。
当然,您也可以在界面生成器中完成整个设置。
关于ios - 删除等宽约束和调整按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52624911/
如果图像的宽度和高度相等,我如何添加类“相等”。 这是我的代码: var img = $('img', this); var width = img.width(); var height = img
任何人都可以告诉我涵盖大部分 unicode 字符的等宽字体吗?如果没有,那么包含大部分欧洲语言字符集的等宽字体? 最佳答案 我也在寻找单色空间、丰富的 Unicode 字体。到目前为止,我使用 De
我编写了一个程序来拍摄照片并创建 ASCII 表示(ASCII 艺术)。起初,我将 ASCII 字符串写入控制台,但现在我有了一个保存文本的 JLabel。但是,JLabel 输出是不规则的,不像控制
如果我有生成的列表 我要分成几列 like this是否有可能以某种方式让列与最宽的列一样宽 . 我有一个下拉导航,目前我在 上只有一个固定宽度s 但对于较小的导航元素,如“常见问题解答”,有很多
我对编程很陌生。 我试图让三个 col-md-4 具有相同的宽度。我假设如果在 HTML 中正确引用了 Bootstrap,则不需要 CSS。任何建议将不胜感激。 代码: /*NAV LOGO*/ .
是否可以像这样制作一个纯 CSS 解决方案: 元素有一些最小宽度。 它们应该动态增长以填充所有容器宽度,然后换行 列表中的所有元素都应具有相同的宽度。 现在是这样的: 这也是我希望它看起来像的样子(我
我正在尝试通过 flexbox 创建三行,其中将包含可变数量的列(顶部和底部的行将在数量上匹配)和一个中间列,它只是一个列。 由于列数是可变的,因此父级上没有设置宽度。 我正在努力让中间列的宽度与顶部
是否可以像这样制作一个纯 CSS 解决方案: 元素有一些最小宽度。 它们应该动态增长以填充所有容器宽度,然后换行 列表中的所有元素都应具有相同的宽度。 现在是这样的: 这也是我希望它看起来像的样子(我
我将对象动态添加到面板,然后添加到我的边框布局。我需要西部、中心和东部的大小都相等。这是我目前所拥有的: static int width = 300;//Screen width static in
我有一列 4 个元素。由于内容不同,所有元素的宽度都不同。使用 flexbox,有谁知道如何使所有元素与最大元素的宽度相同,同时保持它们全部居中? 这是我目前拥有的。 .container { d
我正在创建一个表单,我有 2 个并排的 div。这是我当前的 html: First name Middle n
如何并排排列 3 个 UIButton。我正在使用自动布局。我的要求是: 1.无论设备如何,它们都应该是等宽的 2.从 View 的开始到结束垂直占据 我尝试了不同的方法,我没能实现。是否可以通过界面
我在 flexbox 中使用 box-sizing: border-box; 具有不同的 border 厚度。我希望 flexbox 中的元素具有相等的宽度,但它会计算没有边框的元素的 width。
我在 flexbox 中使用 box-sizing: border-box; 具有不同的 border 厚度。我希望 flexbox 中的元素具有相等的宽度,但它会计算没有边框的元素的 width。
我是一名优秀的程序员,十分优秀!