iOS自定義選擇框代碼分享
更新時(shí)間:2017年03月16日 11:47:48 作者:弦外雨
這篇文章主要為大家分享了iOS自定義選擇框的實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了iOS自定義選擇框的具體代碼,供大家參考,具體內(nèi)容如下
效果圖:
工程圖:
代碼:
RootViewController.h
#import <UIKit/UIKit.h> #import "CYCustomMultiSelectPickerView.h" @interface RootViewController : UIViewController <CYCustomMultiSelectPickerViewDelegate> { CYCustomMultiSelectPickerView *multiPickerView; UILabel *pickLabel; } @end
RootViewController.m
#import "RootViewController.h" @interface RootViewController () @end @implementation RootViewController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.title=@"ALPickerView"; pickLabel=[[UILabel alloc]initWithFrame:CGRectMake(10, 100, 100, 50)]; pickLabel.backgroundColor=[UIColor orangeColor]; pickLabel.textAlignment=NSTextAlignmentCenter; [self.view addSubview:pickLabel]; } //隨意點(diǎn)擊任意處,彈出選擇框 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { [self initPickerView]; } -(void)initPickerView { for (UIView *view in self.view.subviews) { if ([view isKindOfClass:[CYCustomMultiSelectPickerView class]]) { [view removeFromSuperview]; } } multiPickerView = [[CYCustomMultiSelectPickerView alloc] initWithFrame:CGRectMake(0,[UIScreen mainScreen].bounds.size.height - 260-20, 320, 260+44)]; multiPickerView.backgroundColor = [UIColor clearColor]; multiPickerView.entriesArray = [NSMutableArray arrayWithObjects:@"one",@"two",@"three",@"four",@"five",@"six",@"seven", nil]; multiPickerView.entriesSelectedArray = [NSMutableArray arrayWithObject:@"one"]; multiPickerView.multiPickerDelegate = self; [self.view addSubview:multiPickerView]; [multiPickerView pickerShow]; } #pragma -mark -picker delegate //點(diǎn)擊確定要執(zhí)行的操作 -(void)returnChoosedPickerString:(NSMutableArray *)selectedEntriesArr { NSLog(@"returnChoosedPickerString"); NSMutableArray* newArray = [NSMutableArray array]; for (NSString* str in selectedEntriesArr) { [newArray addObject:str]; } NSString *endStr = [newArray componentsJoinedByString:@","]; pickLabel.text=endStr; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
IOS購(gòu)物車(chē)界面實(shí)現(xiàn)效果示例
本篇文章主要介紹了IOS購(gòu)物車(chē)界面實(shí)現(xiàn)效果示例,有需要了解的朋友可參考。希望此文章對(duì)各位有所幫助。2017-02-02iOS開(kāi)源一個(gè)簡(jiǎn)單的訂餐app UI框架
這篇文章主要介紹了iOS開(kāi)源一個(gè)簡(jiǎn)單的訂餐app UI框架,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10iOS開(kāi)發(fā)之級(jí)聯(lián)界面(推薦界面)搭建原理
這篇文章主要為大家詳細(xì)介紹了iOS級(jí)聯(lián)界面(推薦界面)搭建原理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08iOS runtime forwardInvocation詳解及整理
這篇文章主要介紹了 iOS runtime forwardInvocation詳解及整理的相關(guān)資料,需要的朋友可以參考下2017-02-02iOS實(shí)現(xiàn)賬號(hào)、密碼記住功能
這篇文章主要為大家詳細(xì)介紹了iOS實(shí)現(xiàn)賬號(hào)、密碼記住功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03