iOS中UIPickerview的应用和去掉边线
来源:互联网 发布:淘宝辅助软件哪个最好 编辑:程序博客网 时间:2024/06/05 02:30
1:uipickerview的使用
2:返回一个富文本的显示
3:设置cell的行高
4:设置返回一个自定义的view
5:设置pickerview的上下两条线的颜色或者隐藏掉
- picker view的实例化
self.pickView = [[UIPickerView alloc] init]; self.pickView.dataSource = self; self.pickView.delegate = self; self.pickView.userInteractionEnabled = NO; [self.backGroundView addSubview:self.pickView]; self.pickView.showsSelectionIndicator = NO;
设置self.pickView.userInteractionEnabled = NO; 就是让用户不能点击有翻滚的效果
2. 使用
几个必须的使用函数
#pragma mark - uipickview DELEGATE-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 1;}-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { return self.dataArry.count;}
- 2.1 返回一个富文本编辑效果
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component{ NSString * reStr = self.dataArry[row]; // 创建一个富文本 NSMutableAttributedString * attriStr = [[NSMutableAttributedString alloc] initWithString:reStr]; // 修改富文本中的不同文字的样式 [attriStr addAttribute:NSForegroundColorAttributeName value:YSColor(88, 164, 240) range:NSMakeRange(0, reStr.length)]; //[attriStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, reStr.length)]; ((UIView *)[self.pickView.subviews objectAtIndex:1]).backgroundColor = [YSColor(255, 255, 255) colorWithAlphaComponent:0.5]; return attriStr;}
- 2.2 设置cell的行高
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component { return 20;}
- 2.3 设置cell为custom的view
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view { CGFloat width = 125.0f; CGFloat height = 20.0f; UIView * myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, height)]; myView.backgroundColor = [UIColor clearColor]; UILabel * complateLabel = [[UILabel alloc] init]; complateLabel.center = myView.center; complateLabel.bounds = CGRectMake(0, 0, width, height); complateLabel.textColor = YSColor(88, 164, 240); complateLabel.textAlignment = NSTextAlignmentCenter; complateLabel.font = FONTWITHSIZE_LIGHT(14); complateLabel.text = self.dataArry[row]; [myView addSubview:complateLabel]; ((UIView *)[self.pickView.subviews objectAtIndex:1]).backgroundColor = [YSColor(255, 255, 255) colorWithAlphaComponent:0.5]; if (IS_IOS7) { ((UIView *)[self.pickView.subviews objectAtIndex:2]).backgroundColor = [YSColor(255, 255, 255) colorWithAlphaComponent:0.5]; } return myView;}
这里的
((UIView *)[self.pickView.subviews objectAtIndex:1]).backgroundColor = [YSColor(255, 255, 255) colorWithAlphaComponent:0.5];((UIView *)[self.pickView.subviews objectAtIndex:2]).backgroundColor = [YSColor(255, 255, 255) colorWithAlphaComponent:0.5];
是设置pickview的上下两条线的颜色,或者隐藏他
更多装逼技能,请关注洲洲个的公众号,不定期有干货退出
0 0
- iOS中UIPickerview的应用和去掉边线
- MPAndroidChart去掉纵向网格线和左右边线
- 用于去掉button外部的边线
- iOS UIPickerView的常见属性和方法
- iOS UIPickerView的使用
- iOS-中国省市区plist(续)UIPickerView的应用
- iOS学习笔记——UIPickerView的简单应用
- IOS中的UIPickerView和UIDatePicker
- 在ios中对定制的UIPickerView 进行数据定位
- iOS系统UIPickerView的简单使用和方法属性介绍
- iOS UIPickerView的简单使用和数组越界问题
- transform3D和fixed冲突问题;ios的输入框头部边线阴影问题
- Android中Edittext的自定义文本框边线
- iOS开发 UIPickerView的使用
- ios-day10-03(省份和城市联动。UIPickerView的使用、使用UIPickerView的reloadComponent:方法刷新某一列)
- swift中UIPickerView的使用
- swift中UIPickerView的使用
- iOS UIPickerView
- 统计之都统计分析和R语言方面的图书
- 配置Tableau Desktop连接SparkSQL
- 模型融合的主要方法
- Android 自定义可拖动尺子控件
- 1024_01排序
- iOS中UIPickerview的应用和去掉边线
- darwin Stream Server源码分析
- 第七周项目 求两点之间的距离 成员函数
- Android EditText 银行卡四位空一格
- HashMap 源码解析
- 移动APP开发的需求分析
- 聚簇索引和非聚簇索引的区别
- Android Application对象必须掌握的七点
- 设置共享访问时提示需要密码的解决