Saturday 15 January 2011

ios - Auto layout equal space between UIButtons -



ios - Auto layout equal space between UIButtons -

this question has reply here:

springs in auto layout: distribute views evenly, constraints, in xcode 5 2 answers

i'm new in auto layout reading bit questions here in stack i'm trying align 5 uibuttons @ bottom of cell have equal space (of 7 points example), tried using code , doesn't work.

my question - how can using 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] ;

error:

2014-10-09 03:04:07.501 human response[2972:781746] unable simultaneously satisfy constraints. @ to the lowest degree 1 of constraints in next list 1 don't want. seek this: (1) @ each constraint , seek figure out don't expect; (2) find code added unwanted constraint or constraints , prepare it. (note: if you're seeing nsautoresizingmasklayoutconstraints don't understand, refer documentation 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 )>" ) effort recover breaking constraint <nslayoutconstraint:0x1558b4c0 h:[uibutton:0x15598410(20)]> create symbolic breakpoint @ uiviewalertforunsatisfiableconstraints grab in debugger. methods in uiconstraintbasedlayoutdebugging category on uiview listed in <uikit/uiview.h> may helpful. 2014-10-09 03:04:07.633 human response[2972:781746] unable simultaneously satisfy constraints. @ to the lowest degree 1 of constraints in next list 1 don't want. seek this: (1) @ each constraint , seek figure out don't expect; (2) find code added unwanted constraint or constraints , prepare it. (note: if you're seeing nsautoresizingmasklayoutconstraints don't understand, refer documentation 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 )>" )

the way i've found ib create spacer views between views want distribute evenly, of edges connected neighboring edges of views want distribute evenly. give them variable width/height, , add together constraints of spacer views must have same width/height.

it's tedious set up, work.

ios objective-c uibutton autolayout

No comments:

Post a Comment