ios - iPhone auto layout images arrangement issue -
i want arrange 3 images on iphone & ipad using auto layout.
3 images should rezise preserving aspect ratio, , width of 3 images should same. same space left , right sides 3 images.
see example figure (figure shows landscape , portrait mode) on link:
portrait: http://i.imgur.com/9kvxate.png
landscape: http://i.imgur.com/tdjj9k6.png
it possible programatically getting width , height of screen/view want using auto-layouts
programatically:
//inside method //- (void) didrotatefrominterfaceorientation: (uiinterfaceorientation)frominterfaceorientation //main_view view in 3 images kept //imageview1, imageview2, imageview3 3 image views imageview1.frame = cgrectmake(main_view.frame.origin.x + 3, main_view.frame.origin.y + 30, ((main_view.frame.size.width / 3)-4), ((main_view.frame.size.width / 3) - 4) * (82.0/75.0)); imageview2.frame = cgrectmake(imageview1.frame.size.width + 6, main_view.frame.origin.y + 30, ((main_view.frame.size.width / 3)-4), ((main_view.frame.size.width / 3) - 4) * (82.0/75.0)); imageview3.frame = cgrectmake(imageview2.frame.size.width + imageview1.frame.size.width + 9, main_view.frame.origin.y + 30, ((main_view.frame.size.width / 3)-4), ((main_view.frame.size.width / 3) - 4) * (82.0/75.0));
main_view changes size(width,height). (imageview1 width) (main_view width / 3), preserves aspect ratio too.
programatically works perfect
this quite easy autolayout in interfacebuilder well. but, there few things might have sacrifice when using autolayout in interface builder. want arrange items items in storyboard. steps follows:
- add 3 views interface builder, so,
- select 3 pictures , add new constraint in interface builder button |---|, , select equal width , equal height.
- then, again select 3 views , menu select editor -> align -> top edges
- select left view , give offset left,
- select right view , give offset right,
- select 1 of view , give offset @ top , bottom.
- select second view control + drag first , select horizontal separation , give constant value , same second , third view.
now, constraints complete. happen when select multiple views @ same time , add constraint, might not have been added 1 of views. might have resolve looking error , seeing constraints view, if constraints added there.
you keep constraint separate view top margin or bottom margin , create outlet , change suit need or set parameter in storyboard itself.
here screenshot ipad simulator horizontal orientation.
and here vertical orientation,
i hope have answered question. let me know if have this.
Comments
Post a Comment