ios – 自动布局UIButtons之间的空间相等

ios – 自动布局UIButtons之间的空间相等,第1张

概述参见英文答案 > Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5                                    2个 我是自动布局的新手,所以在堆栈中读取一些问题我试图在单元格的底部对齐我的5个UIButton以获得相等的空间(例如7个点),我尝试使用代码并且它没有’ 参见英文答案 > Springs in Auto Layout: Distribute views evenly,with constraints,in Xcode 52个
我是自动布局的新手,所以在堆栈中读取一些问题我试图在单元格的底部对齐我的5个UIbutton以获得相等的空间(例如7个点),我尝试使用代码并且它没有’工作.

我的问题是 – 我怎样才能使用Interface Builder?

UIbutton *button1 = self.btnFavorite,*button2 = self.btnCalendar,*button3 = self.btnEmail,*button4 = self.btnMessage,*button5 = self.btnCall;    NSMutableArray *constraintsForbuttons = [[NSMutableArray alloc] init];    float unusedHorizontalSpace = self.bounds.size.wIDth - button1.intrinsicContentSize.wIDth - button2.intrinsicContentSize.wIDth - button3.intrinsicContentSize.wIDth - button4.intrinsicContentSize.wIDth - button5.intrinsicContentSize.wIDth;    NSNumber *spaceBetweenEachbutton =  [NSNumber numberWithfloat: unusedHorizontalSpace / 5 ] ;    [constraintsForbuttons addobjectsFromArray:[NSLayoutConstraint                                                constraintsWithVisualFormat: @"H:|-(space)-[button1]-(space)-[button2]-(space)-[button3]-(space)-[button4]-(space)-[button5]-(space)-|"                                                options:NSLayoutFormatAlignAllCenterY                                                metrics:@{@"space":spaceBetweenEachbutton}                                                vIEws:NSDictionaryOfVariableBindings(button1,button2,button3,button4,button5)]];    [constraintsForbuttons addobjectsFromArray:[NSLayoutConstraint constraintsWithVisualFormat: @"V:|[button1]"                                                                                        options: 0                                                                                        metrics: nil                                                                                          vIEws: NSDictionaryOfVariableBindings(button1) ] ] ;    [self addConstraints:constraintsForbuttons] ;

错误:

2014-10-09 03:04:07.501 Human Response[2972:781746] Unable to simultaneously satisfy constraints.    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; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSautoresizingMaskLayoutConstraints that you don't understand,refer to the documentation for the UIVIEw property translatesautoresizingMaskIntoConstraints) (    "<NSLayoutConstraint:0x1568f260 H:[UIbutton:0x1568f100(20)]>","<NSLayoutConstraint:0x15690b90 H:[UIbutton:0x15690fc0(20)]>","<NSLayoutConstraint:0x156921c0 H:[UIbutton:0x15692d00(20)]>","<NSLayoutConstraint:0x1568d4f0 H:[UIbutton:0x1568d8e0(20)]>","<NSLayoutConstraint:0x1558b4c0 H:[UIbutton:0x15598410(20)]>","<NSLayoutConstraint:0x155993d0 H:|-(-60)-[UIbutton:0x15598410]   (names: '|':UItableVIEwCellContentVIEw:0x15673e40 )>","<NSLayoutConstraint:0x15599550 H:[UIbutton:0x15598410]-(-60)-[UIbutton:0x1568d8e0]>","<NSLayoutConstraint:0x155996e0 H:[UIbutton:0x1568d8e0]-(-60)-[UIbutton:0x15692d00]>","<NSLayoutConstraint:0x15599740 H:[UIbutton:0x15692d00]-(-60)-[UIbutton:0x15690fc0]>","<NSLayoutConstraint:0x155997a0 H:[UIbutton:0x15690fc0]-(-60)-[UIbutton:0x1568f100]>","<NSLayoutConstraint:0x15599800 H:[UIbutton:0x1568f100]-(-60)-|   (names: '|':UItableVIEwCellContentVIEw:0x15673e40 )>")Will attempt to recover by breaking constraint <NSLayoutConstraint:0x1558b4c0 H:[UIbutton:0x15598410(20)]>Make a symbolic breakpoint at UIVIEwAlertForUnsatisfiableConstraints to catch this in the deBUGger.The methods in the UIConstraintBasedLayoutDeBUGging category on UIVIEw Listed in <UIKit/UIVIEw.h> may also be helpful.2014-10-09 03:04:07.633 Human Response[2972:781746] Unable to simultaneously satisfy constraints.    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; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSautoresizingMaskLayoutConstraints that you don't understand,refer to the documentation for the UIVIEw property translatesautoresizingMaskIntoConstraints) (    "<NSLayoutConstraint:0x155a2de0 H:[UIbutton:0x155a2fc0(20)]>","<NSLayoutConstraint:0x155a33d0 H:[UIbutton:0x155a32d0(20)]>","<NSLayoutConstraint:0x155a3750 H:[UIbutton:0x155a3620(20)]>","<NSLayoutConstraint:0x155a1bc0 H:[UIbutton:0x155a1a60(20)]>","<NSLayoutConstraint:0x155a3df0 H:[UIbutton:0x155a3cc0(20)]>","<NSLayoutConstraint:0x156a4770 H:|-(-60)-[UIbutton:0x155a3cc0]   (names: '|':UItableVIEwCellContentVIEw:0x155a2150 )>","<NSLayoutConstraint:0x156a47b0 H:[UIbutton:0x155a3cc0]-(-60)-[UIbutton:0x155a1a60]>","<NSLayoutConstraint:0x156a4840 H:[UIbutton:0x155a1a60]-(-60)-[UIbutton:0x155a3620]>","<NSLayoutConstraint:0x156a48c0 H:[UIbutton:0x155a3620]-(-60)-[UIbutton:0x155a32d0]>","<NSLayoutConstraint:0x156a4920 H:[UIbutton:0x155a32d0]-(-60)-[UIbutton:0x155a2fc0]>","<NSLayoutConstraint:0x1569fa50 H:[UIbutton:0x155a2fc0]-(-60)-|   (names: '|':UItableVIEwCellContentVIEw:0x155a2150 )>")
解决方法 我发现使用IB执行此 *** 作的唯一方法是在要均匀分布的视图之间创建间隔视图,其所有边连接到要均匀分布的视图的相邻边.您可以为它们指定可变宽度/高度,然后添加约束,表示所有间隔视图必须具有相同的宽度/高度.

设置起来非常繁琐,但确实有效.

总结

以上是内存溢出为你收集整理的ios – 自动布局UIButtons之间的空间相等全部内容,希望文章能够帮你解决ios – 自动布局UIButtons之间的空间相等所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1109703.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存