本文实例为大家分享了iOS自定义选择框的具体代码,供大家参考,具体内容如下
效果图:
工程图:
代码:
RootViewController.h
# import & lt; UIKit/UIKit.h> #进口“CYCustomMultiSelectPickerView.h” @ interface RootViewController: ui & lt; CYCustomMultiSelectPickerViewDelegate> { CYCustomMultiSelectPickerView * multiPickerView; UILabel * pickLabel; } @end >之前RootViewController.m
#进口“RootViewController.h” @ interface RootViewController () @end @ implementation RootViewController - (id) initWithNibName:(NSString *) nibNameOrNil包:nibBundleOrNil (NSBundle *) { 自我=[超级initWithNibName: nibNameOrNil包:nibBundleOrNil]; 如果(自我){//自定义初始化 } 回归自我; } - (void) viewDidLoad { (超级viewDidLoad);//加载后任何额外设置视图。 self.title=@“ALPickerView”; pickLabel=[[UILabel alloc] initWithFrame: CGRectMake (100、100、50)]; pickLabel。写成backgroundColor=[用户界面颜色orangeColor]; pickLabel.textAlignment=NSTextAlignmentCenter; (自我。视图addSubview pickLabel):; }//随意点击任意处,弹出选择框 - (void) touchesBegan: NSSet(*)触摸withEvent: UIEvent(*)事件 { (自我initPickerView); } - (void) initPickerView { (UIView *视图self.view.subviews) { 如果([视图isKindOfClass: [CYCustomMultiSelectPickerView类]]){ (查看removeFromSuperview); } } multiPickerView=[[CYCustomMultiSelectPickerView alloc] initWithFrame: CGRectMake (0, [UIScreen mainScreen] .bounds.size。身高- 260 - 20、320、260 + 44)]; multiPickerView。写成backgroundColor=[用户界面颜色clearColor]; multiPickerView。entriesArray=[NSMutableArray arrayWithObjects: @“一”@“两个”@“三”@“四”@“五”@“六”@“七”,nil); multiPickerView。entriesSelectedArray=[NSMutableArray arrayWithObject: @“一”); multiPickerView。multiPickerDelegate=自我; (自我。视图addSubview multiPickerView):; [multiPickerView pickerShow]; } # pragma马克选择委托//点击确定要执行的操作 - (void) returnChoosedPickerString: selectedEntriesArr (NSMutableArray *) { NSLog (@“returnChoosedPickerString”); NSMutableArray * newArray=[NSMutableArray数组); (NSString * str selectedEntriesArr) { [newArray addObject: str); } NSString * endStr=[newArray componentsJoinedByString: @”、“); pickLabel.text=endStr; } - (void) didReceiveMemoryWarning { (超级didReceiveMemoryWarning);//处理任何资源都可以被重新创建。 } @end >之前以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
iOS自定义选择框代码分享