Swift/iOS - Whats the alternative to multiple android drop down lists -
i'm new ios , swift. i've been making android app couple years now. i'm learning swift , making ios devices.
i need alternative ways of drop down lists, since thats i've using in android.
i've been researching uipickerviews, uipopovers table views , more.
twist is, need multiple alternate of drop down lists in 1 viewcontroller.
here view in android app, want pretty similar in ios version.
i've been building survey applications last couple of months , exact problem has come several times. while uipickerview
makes sense, doesn't allow user see more few options @ time , doesn't scale iphone 4s 6+ or ipad.
the first thing recommend create button drop down menu. i've found looks remotely button works making hyperlink or inline what's surrounding doesn't work ux perspective.
all is a. uibutton thin border around corner radius of ~5.
as actual drop down, i've found popovers pretty effective. easiest implementation me using uialertcontroller
. (this available in ios 8+ should fine if you're working in swift anyway.) uialertcontroller
can have large number of options, cancel button that's accessible, title, message presented user in standard way. can set actions each button when controller created don't have work delegates @ keeps code cleaner.
here's alert controller previous example looks like. on iphone 5s in landscape smallest layout possible scales automatically needed screen size , offers similar experience user.
when user has selected answer, update button text match new answer.
instead of using uialertcontroller
, have created own custom pop table view i've found myself recreating alert controller of , found more difficult it's worth layout right on every device. said, uialertcontroller
offers nothing way of customizing how looks, can deal breaker some.
i feel should add reason use uialertcontroller
instead of uipickerview
intentional since allows user see more options simultaneously , makes use of available screen size on ipad , larger iphones. additionally, feedback after making selection instantaneous view disappears selection made, cancel
standard action allows user not make selection, , doesn't require user scroll if there few options means selection can made in 1 tap.
here's code used produce button , corresponding uialertcontroller
:
if (self.question.placeholdertext) { [self.answerbutton settitle:nslocalizedstring(self.question.placeholdertext, @"") forstate:uicontrolstatenormal]; } else { [self.answerbutton settitle:nslocalizedstring(@"please select one", nil) forstate:uicontrolstatenormal]; } [self.answerbutton settitle:[self paddedstring:self.answerbutton.titlelabel.text] forstate:uicontrolstatenormal]; self.answerbutton.titlelabel.textalignment = nstextalignmentleft; self.answerbutton.contenthorizontalalignment = uicontrolcontenthorizontalalignmentleft; self.answerbutton.titlelabel.font = [uifont appfont]; [self.answerbutton settitlecolor:[uicolor appcolor] forstate:uicontrolstatenormal]; [self.answerbutton addtarget:self action:@selector(longlistlabeltapped) forcontrolevents:uicontroleventtouchupinside]; self.answerbutton.backgroundcolor = [uicolor colorwithwhite:0.0f alpha:0.0001f]; self.answerbutton.titlelabel.layer.bordercolor = [uicolor appcolor].cgcolor; self.answerbutton.titlelabel.layer.borderwidth = 1.0f; self.answerbutton.titlelabel.layer.cornerradius = 5.0f; - (nsstring *)paddedstring:(nsstring *)input { //this adds space around button title make better return [nsstring stringwithformat:@" %@ ", input]; }
to create uialertcontroller
, you'll need array of options.
_optionscontroller = [uialertcontroller alertcontrollerwithtitle:self.question.longlisttitle message:nil preferredstyle:uialertcontrollerstylealert]; uialertaction *cancelaction = [uialertaction actionwithtitle:@"cancel" style:uialertactionstyledestructive handler:^(uialertaction *action) { }]; [_optionscontroller addaction:cancelaction]; (nsstring *optionname in self.question.possibleanswers) { uialertaction *action = [uialertaction actionwithtitle:optionname style:uialertactionstyledefault handler:^(uialertaction *action) { // selected answer [self.answerbutton settitle:[self paddedstring:optionname] forstate:uicontrolstatenormal]; }]; [_optionscontroller addaction:action]; }
Comments
Post a Comment