Friday 15 August 2014

ios - How flexible size elements in visual format auto layout decide which predicate to use -



ios - How flexible size elements in visual format auto layout decide which predicate to use -

in using auto layout programmatically visual format, confused how makes decisions when given 2 predicates. example, next constraint:

"h:[mytextview(>=300,<=700)]"

so far, on every device try, whether iphone 5s, 6 or ipad, width 300. in case width greater 300? also, ios 7 deployment target app, using swift.

essentially, want view fill of screen's width on iphone, little more half on ipad.

my solution

based on rdelmar's answer.

self.view.addconstraint(nslayoutconstraint( item:self.infotextview, attribute:.width, relatedby:.equal, toitem:self.view, attribute:.width, multiplier:0.23, constant:228))

you can't utilize >= , <= constraints way, because when evaluate look value between 2 satisfy it, scheme picks 1 or other. in ios 8, can utilize size classes give different constraints different size screens.

if you're programming ios 7, need either check device you're on, , set constraints accordingly, or create width relative width of view. think have utilize other constraint method, constraintwithitem:attribute:relatedby:toitem:attribute:multiplier:constant:, though this. using multiplier , constant, create view, 300 wide on iphone, 400 on ipad (a multiplier of .223 , constant of 228 320 point wide phone , 768 point wide ipad).

ios autolayout predicate visual-format-language

No comments:

Post a Comment