1. <tfoot id='7jnOi'></tfoot>

      <bdo id='7jnOi'></bdo><ul id='7jnOi'></ul>

    <small id='7jnOi'></small><noframes id='7jnOi'>

  2. <i id='7jnOi'><tr id='7jnOi'><dt id='7jnOi'><q id='7jnOi'><span id='7jnOi'><b id='7jnOi'><form id='7jnOi'><ins id='7jnOi'></ins><ul id='7jnOi'></ul><sub id='7jnOi'></sub></form><legend id='7jnOi'></legend><bdo id='7jnOi'><pre id='7jnOi'><center id='7jnOi'></center></pre></bdo></b><th id='7jnOi'></th></span></q></dt></tr></i><div id='7jnOi'><tfoot id='7jnOi'></tfoot><dl id='7jnOi'><fieldset id='7jnOi'></fieldset></dl></div>
  3. <legend id='7jnOi'><style id='7jnOi'><dir id='7jnOi'><q id='7jnOi'></q></dir></style></legend>

      在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法?

      时间:2023-07-07

        <i id='6Jx8O'><tr id='6Jx8O'><dt id='6Jx8O'><q id='6Jx8O'><span id='6Jx8O'><b id='6Jx8O'><form id='6Jx8O'><ins id='6Jx8O'></ins><ul id='6Jx8O'></ul><sub id='6Jx8O'></sub></form><legend id='6Jx8O'></legend><bdo id='6Jx8O'><pre id='6Jx8O'><center id='6Jx8O'></center></pre></bdo></b><th id='6Jx8O'></th></span></q></dt></tr></i><div id='6Jx8O'><tfoot id='6Jx8O'></tfoot><dl id='6Jx8O'><fieldset id='6Jx8O'></fieldset></dl></div>
          <tbody id='6Jx8O'></tbody>

            <small id='6Jx8O'></small><noframes id='6Jx8O'>

            • <bdo id='6Jx8O'></bdo><ul id='6Jx8O'></ul>
              <tfoot id='6Jx8O'></tfoot>

              <legend id='6Jx8O'><style id='6Jx8O'><dir id='6Jx8O'><q id='6Jx8O'></q></dir></style></legend>
                本文介绍了在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我查看了很多答案,它们看起来都非常复杂!最近我在看 this answer 虽然我不希望将按钮放在视图中.

                I've looked through many answers and they all seem very complex! Most recently I was looking at this answer although I'd prefer not to have to put my buttons inside views.

                我有 6 个尺寸相同的 UIButton.我想在我的根视图控制器的整个宽度和底部均匀地水平放置它们.

                I have 6 UIButtons that are all the same dimensions. I want to space them evenly horizontally across the full width and at the bottom of my root view controller.

                |                                      |
                |                                      |
                |  [b1]  [b2]  [b3]  [b4]  [b5]  [b6]  |
                ________________________________________
                

                以编程方式实现这一目标的最简单方法是什么?

                What is the simplest way to achieve this programmatically?

                推荐答案

                我认为这比接受答案上的链接更简单.好的,首先让我们创建一些按钮:

                I think this is simpler than the link on the accepted answer. Ok, firstly lets create some buttons:

                UIButton *button1 = [UIButton buttonWithType:UIButtonTypeSystem];
                button1.translatesAutoresizingMaskIntoConstraints = NO;
                [button1 setTitle:@"Btn1" forState:UIControlStateNormal];
                

                ...为 6 个按钮执行 6 次,但是你喜欢然后将它们添加到视图中:

                ... do that 6 times for 6 buttons, however you like then add them to the view:

                [self.view addSubview:button1];
                [self.view addSubview:button2];
                [self.view addSubview:button3];
                [self.view addSubview:button4];
                [self.view addSubview:button5];
                [self.view addSubview:button6];
                

                将一个按钮固定到视图底部:

                Fix one button to the bottom of your view:

                [self.view addConstraint:[NSLayoutConstraint constraintWithItem:button1 attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeBottom multiplier:1 constant:0]];
                

                然后告诉所有按钮宽度相等,并在宽度上均匀分布:

                Then tell all the buttons to be equal width and spread out equally across the width:

                NSDictionary *views = NSDictionaryOfVariableBindings(button1, button2, button3, button4, button5, button6);
                [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[button1][button2(==button1)][button3(==button1)][button4(==button1)][button5(==button1)][button6(==button1)]|" options:NSLayoutFormatAlignAllBottom metrics:nil views:views]];
                

                结果:

                这篇关于在视图控制器的宽度上水平均匀分布 UIButton 的最简单方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:如何增加 UIButton 的点击区域? 下一篇:UIButton 在 iOS 5.x 中不起作用,在 iOS 6.x 中一切正常

                相关文章

                <i id='i8oq8'><tr id='i8oq8'><dt id='i8oq8'><q id='i8oq8'><span id='i8oq8'><b id='i8oq8'><form id='i8oq8'><ins id='i8oq8'></ins><ul id='i8oq8'></ul><sub id='i8oq8'></sub></form><legend id='i8oq8'></legend><bdo id='i8oq8'><pre id='i8oq8'><center id='i8oq8'></center></pre></bdo></b><th id='i8oq8'></th></span></q></dt></tr></i><div id='i8oq8'><tfoot id='i8oq8'></tfoot><dl id='i8oq8'><fieldset id='i8oq8'></fieldset></dl></div>

                  1. <tfoot id='i8oq8'></tfoot>
                      <bdo id='i8oq8'></bdo><ul id='i8oq8'></ul>
                    <legend id='i8oq8'><style id='i8oq8'><dir id='i8oq8'><q id='i8oq8'></q></dir></style></legend>

                    <small id='i8oq8'></small><noframes id='i8oq8'>