Monday, 15 July 2013

ios - Place UIToolbar at the bottom of the screen above a UITableViewController -



ios - Place UIToolbar at the bottom of the screen above a UITableViewController -

i don't want utilize toolbar of uinavigationcontroller. want utilize separate uitoolbar instead.

requirements:

always visible on screen should remain on it's position @ bottom of uiview (like toolbar of uinavigationcontroller) should adapts it's width (e.g. after rotation) no ib/storyboard solution additionally: don't hide content of uitableview

i want utilize auto layout this. despite code in c#, can provide solution objective-c.

this works in viewdidload on uiviewcontroller, not in viewdidload on uitableviewcontroller:

uiview toolbar = new uiview (); toolbar.backgroundcolor = uicolor.red; toolbar.translatesautoresizingmaskintoconstraints = false; view.addsubview (toolbar); nslayoutconstraint toolbarbottom = nslayoutconstraint.create (toolbar, nslayoutattribute.bottom, nslayoutrelation.equal, bottomlayoutguide, nslayoutattribute.top, 1, 0); nslayoutconstraint toolbarleft = nslayoutconstraint.create (toolbar, nslayoutattribute.left, nslayoutrelation.equal, view, nslayoutattribute.left, 1, 0); nslayoutconstraint toolbarright = nslayoutconstraint.create (toolbar, nslayoutattribute.right, nslayoutrelation.equal, view, nslayoutattribute.right, 1, 0); nslayoutconstraint toolbarheight = nslayoutconstraint.create (toolbar, nslayoutattribute.height, nslayoutrelation.equal, null, nslayoutattribute.noattribute, 1, 40); this.view.addconstraints (new nslayoutconstraint[] { toolbarbottom, toolbarleft, toolbarright, toolbarheight });

for test reasons used uiview instead of uitoolbar. results similar. on uiviewcontroller reddish view shown. on uitableviewcontroller doesn't appear @ all.

i made test without using auto layout:

rectanglef toolbarframe = new rectanglef (0, this.view.bounds.height - 44, this.view.bounds.width, 44); uiview toolbar = new uiview (toolbarframe); toolbar.backgroundcolor = uicolor.red; view.addsubview (toolbar);

here uiview shown on fixed position in table view , separator line shines through. not want, seems possible place uitoolbar on uitableview ...

i used container view. main space table view , under toolbar. works.

these of constraints:

documentlisttop = nslayoutconstraint.create (documentlistcontroller.view, nslayoutattribute.top, nslayoutrelation.equal, toplayoutguide, nslayoutattribute.bottom, 1, 0); //documentlistbottom = nslayoutconstraint.create (documentlistcontroller.view, nslayoutattribute.bottom, nslayoutrelation.equal, bottomlayoutguide, nslayoutattribute.top, 1, 0); ocumentlistbottomtoolbar = nslayoutconstraint.create (documentlistcontroller.view, nslayoutattribute.bottom, nslayoutrelation.equal, toolbar, nslayoutattribute.top, 1, 0); documentlistleft = nslayoutconstraint.create (documentlistcontroller.view, nslayoutattribute.left, nslayoutrelation.equal, view, nslayoutattribute.left, 1, 0); documentlistright = nslayoutconstraint.create (documentlistcontroller.view, nslayoutattribute.right, nslayoutrelation.equal, view, nslayoutattribute.right, 1, 0); toolbarbottom = nslayoutconstraint.create (toolbar, nslayoutattribute.bottom, nslayoutrelation.equal, bottomlayoutguide, nslayoutattribute.top, 1, 0); toolbartop = nslayoutconstraint.create (toolbar, nslayoutattribute.top, nslayoutrelation.equal, documentlistcontroller.view, nslayoutattribute.bottom, 1, 0); toolbarleft = nslayoutconstraint.create (toolbar, nslayoutattribute.left, nslayoutrelation.equal, view, nslayoutattribute.left, 1, 0); toolbarright = nslayoutconstraint.create (toolbar, nslayoutattribute.right, nslayoutrelation.equal, view, nslayoutattribute.right, 1, 0); toolbarheight = nslayoutconstraint.create (toolbar, nslayoutattribute.height, nslayoutrelation.equal, null, nslayoutattribute.noattribute, 1, 44);

the toolbar visible , doesn't hide table view. 1 disadvantage more complex handling (e.g. when in popover, when passing data, ...). perhaps there improve way springs , struts ...

ios uitableview autolayout uitoolbar uitoolbarposition

No comments:

Post a Comment