iOS Development--ui & dropdown pop-up list selection effects

Source: Internet
Author: User
Tags uikit

drop-down popup list selection effect

The button in the right menu, click the Pop up a list to choose, select one, respond to the corresponding event and display the text on the right menu; pop-up drop-down effect using the Lmdropdownview plugin, you can load pod with pod ' Lmdropdownview '; Lmdropdownview is to assign the desired view to it;

Source code Address: Https://github.com/JxbSir/YiYuanYunGou

The effect is as follows:

1: In the main page first define the key and bound view (not written in the attribute is defined such as Btnrigth,dropdownview, etc.):

Btnrigth = [UIButton buttonwithtype:uibuttontypecustom];    [Btnrigth addtarget:self Action: @selector (Btnrightaction) forcontrolevents:uicontroleventtouchupinside];    if (![ Oytool Shardinstance].bisforreview)    {        [self actioncustomnavbtn:btnrigth nrlimage:@ "" htlimage:@ "" title:@ " All categories "];    }    else    {        [self actioncustomnavbtn:btnrigth nrlimage:@ "" htlimage:@ "" title:[dictypename.allvalues OBJECTATINDEX:0]];    }    Self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem alloc] initwithcustomview:btnrigth];    allprotypeview* Tview = [[Allprotypeview alloc] initWithFrame:self.view.bounds];    Tview.delegate = self;    In the drop-down effect view    dropdownview = [[Lmdropdownview alloc] init];    Dropdownview.menubackgroundcolor = [Uicolor whitecolor];    Dropdownview.menucontentview = Tview;

2: Where to set the key to the package:

-(void) ACTIONCUSTOMNAVBTN: (UIButton *) btn nrlimage: (NSString *) nrlimage                  htlimage: (NSString *) Hltimage                     Title: (NSString *) title {    [btn setimage:[uiimage imagenamed:nrlimage] forstate:uicontrolstatenormal];    if (hltimage) {        [btn setimage:[uiimage imagenamed:hltimage] forstate:uicontrolstatehighlighted];    } else {        [btn setimage:[uiimage imagenamed:nrlimage] forstate:uicontrolstatenormal];    }    if (title) {        Btn.titleLabel.font = [Uifont boldsystemfontofsize:13];        [Btn Settitle:title forstate:uicontrolstatenormal];        [Btn Settitle:title forstate:uicontrolstatehighlighted];        [btn Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatenormal];        [btn Settitlecolor:[uicolor Whitecolor] forstate:uicontrolstatehighlighted];    }    [Btn SizeToFit];}

3: Where Btnrightaction responds to event content (primarily for display and hide drop-down effects):

-(void) btnrightaction{    if ([Dropdownview IsOpen])    {        [dropdownview hide];    }    else    {        //[tbviewtype reloaddata];        [Dropdownview ShowInView:self.view withframe:cgrectmake (0, 0, Mainwidth, self.view.bounds.size.height)];}    }

The view code for the 4:allprotypeview drop-down content is as follows (is a list):

. h file Contents #import <UIKit/UIKit.h> @protocol allprotypeviewdelegate-(void) Selectedtypecode: (int) code;@ End@interface Allprotypeview:uiview@property (nonatomic,weak) id<allprotypeviewdelegate> delegate; @end. m File contents        @interface Allprotypeview () <uitableviewdatasource,uitableviewdelegate>{UITableView *tbView;    Nsarray *arroftype;    Nsarray *arroftypeimage;        Nsinteger Indextype; __weak id<allprotypeviewdelegate> Delegate;} @end @implementation allprotypeview@synthesize delegate;-(ID) initWithFrame: (cgrect) frame{self = [Super InitWithFrame    : frame];                if (self) {self.backgroundcolor = [uicolor Redcolor]; Tbview = [[UITableView alloc] Initwithframe:cgrectmake (0, 0, mainwidth, frame.size.height) style:        Uitableviewstylegrouped];        Tbview.delegate = self;        Tbview.datasource = self;        Tbview.backgroundcolor = [Uicolor Whitecolor]; Tbview.separatorstyle = UitableviewcellseparatorstylesingleLine; Tbview.autoresizingmask = Uiviewautoresizingflexiblewidth |        Uiviewautoresizingflexibleheight;                [Self addsubview:tbview]; if (![ Oytool shardinstance].bisforreview) {Arroftype = @[@ "All categories" @ "mobile phone digital" @ "PC Office" @ "Home appliances" @ "Makeup protection" @ "Watch jewellery" @ "other            Goods "];        Arroftypeimage = @[@ "Sort0", @ "sort100", @ "sort106", @ "sort104", @ "Sort2", @ "sort222", @ "sort312"];            } else {arroftype = @[@ "Home appliances" @ "makeup guard" @ "Watch jewellery" @ "other goods"];        Arroftypeimage = @[@ "sort104", @ "Sort2", @ "sort222", @ "sort312"]; }} return self;} #pragma mark-tableview-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{return 1;} -(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return arroftype.count;} -(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return 44;} -(CGFloat) TableView: (UITableView *) TableView heightforheaderinsection: (Nsinteger)section{return 0.1;} -(CGFloat) TableView: (UITableView *) TableView heightforfooterinsection: (Nsinteger) section{return 0.1;} -(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//static    NSString *cellidentifier = @ "Cell";    UITableViewCell *cell = nil;//(uitableviewcell*) [TableView Dequeuereusablecellwithidentifier:cellidentifier];    if (cell = = nil) {cell = [[UITableViewCell alloc] init];    } cell.textLabel.text = [NSString stringwithformat:@ "%@", [Arroftype ObjectAtIndex:indexPath.row]];     nsstring* name = [Arroftypeimage ObjectAtIndex:indexPath.row];        if (Indexpath.row = = indextype) {name = [NSString stringwithformat:@ "%@_checked", name];                Cell.textLabel.textColor = Maincolor;        uiimageview* Imgok = [[Uiimageview alloc] Initwithframe:cgrectmake (mainWidth-32, 14, 20, 16)];        Imgok.image = [UIImage imagenamed:@ "Screening_select"]; [Cell Addsubview:imgok];   } else {name = [NSString stringwithformat:@ "%@_normal", name];    } uiimageview* img = [[Uiimageview alloc] Initwithframe:cgrectmake (16, 10, 24, 24)];    Img.image = [UIImage imagenamed:name];    [Cell addsubview:img]; return cell;} -(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{[TableView    Deselectrowatindexpath:indexpath Animated:yes];    Indextype = Indexpath.row;        [Tbview Reloaddata]; if (delegate) {nsstring* code = [[Arroftypeimage ObjectAtIndex:indexPath.row] Stringbyreplacingoccurrencesofstri        ng:@ "Sort" withstring:@ "" ";    [Delegate Selectedtypecode:[code Intvalue]; }} @end

Note: The list has a binding is selected, it shows the effect is not the same, at the time of the release of the identifier is re-assigned to pass through delegate it back to the main view control device;

5: The main controller in response to the above delegate content is:

-(void) Selectedtypecode: (int) code{    icodetype = code;    [Dropdownview hide];        nsstring* key = [NSString stringwithformat:@ "%d", code];    nsstring* name = [Dictypename Objectforkey:key];        [Self actioncustomnavbtn:btnrigth nrlimage:@ "" htlimage:@ "0" title:name];       Rebind List display content    __weak typeof (self) wself = self;    Curpage = 1;    [Self getdata:^{        __strong typeof (wself) sself = wself;        Sself->listnew = nil;    }];}

iOS Development--ui & dropdown pop-up list selection effects

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.