服务器之家

服务器之家 > 正文

iOS自定义选择框代码分享

时间:2021-03-09 15:57     来源/作者:弦外雨

本文实例为大家分享了ios自定义选择框的具体代码,供大家参考,具体内容如下

效果图:

iOS自定义选择框代码分享

工程图:

iOS自定义选择框代码分享

代码:

rootviewcontroller.h

?
1
2
3
4
5
6
7
8
9
10
11
12
#import <uikit/uikit.h>
#import "cycustommultiselectpickerview.h"
 
 
@interface rootviewcontroller : uiviewcontroller
<cycustommultiselectpickerviewdelegate>
{
 cycustommultiselectpickerview *multipickerview;
 uilabel *picklabel;
}
 
@end

rootviewcontroller.m

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#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];
}
//随意点击任意处,弹出选择框
-(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
//点击确定要执行的操作
-(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

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部