PickView选中某一行的字体变化
来源:互联网 发布:域名抢注服务 编辑:程序博客网 时间:2024/06/06 17:26
要求是选中某一行的时候字体变化,代码如下
.h<UIPickerViewDataSource,UIPickerViewDelegate>
@property (assign,nonatomic)NSInteger selectedRow;
.m
-(void)viewDidLoad{ [super viewDidLoad]; self.timeArray = [[NSArray alloc]initWithObjects:@"0",@"2",@"4",@"6",@"8",@"10",@"12", nil]; self.selectedRow = -1; }
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ return [self.timeArray count];}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ NSString *timeString = self.timeArray[row];}
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ UILabel* pickerLabel = (UILabel*)view; if (!pickerLabel) { pickerLabel = [[UILabelalloc]init]; pickerLabel.minimumScaleFactor =0.5; pickerLabel.adjustsFontSizeToFitWidth =YES; [pickerLabel setTextAlignment:NSTextAlignmentCenter]; [pickerLabel setBackgroundColor:[UIColorclearColor]]; } if (row ==self.selectedRow) { NSString *selectString = [self.timeArrayobjectAtIndex:self.selectedRow]; NSDictionary *attributeDict =@{NSForegroundColorAttributeName : [UIColororangeColor]}; NSMutableAttributedString *attributedString = [[NSMutableAttributedStringalloc]initWithString:selectStringattributes:attributeDict]; NSRange stringRange = {0,[attributedStringlength]}; [attributedStringaddAttribute:NSUnderlineStyleAttributeNamevalue:[NSNumbernumberWithInteger:NSUnderlineStyleSingle]range:stringRange]; pickerLabel.attributedText = attributedString; }else{ pickerLabel.text=[selfpickerView:pickerViewtitleForRow:rowforComponent:component]; } return pickerLabel;}
return timeString; }-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ //获取对应列,对应行的数据 self.pickTimeString=self.timeArray[row]; self.selectedRow = row; [self.picker selectRow:self.selectedRow inComponent:0 animated:YES]; [self.picker reloadComponent:0]; }-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{ return 30;}-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{ return 30;}
实现效果:1 0
- PickView选中某一行的字体变化
- 选中DataGrid的某一行
- jquery 选中某一行
- 自定义pickview的高度
- 自定义pickview的高度
- 自定义pickview的高度
- PickView简单的依赖
- pickView的用法
- iOS自定义的PickView
- listview选中某一行,选中行高亮显示
- 【Android】Listview可以选择多行,点击选中行item字体颜色变化
- CListCtrl 取消选中某一行
- 如何判断GridView控件的某一行是否被选中
- 如何判断GridView控件的某一行是否被选中
- C#在RichTexBox里选中某一行的字符
- ListView某一行被选中后显示不同的样式
- 关于LWUIT的table让选中的某一列的某一行点击可以编辑问题
- jquery table表格 获取选中的某一行和某一列的值
- Hadoop RPC协议之 ProtobufRpcEngine
- 服务器集群视频云的特点应该注意哪些?
- plsql developer调试触发器
- java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
- 发送邮件(java)
- PickView选中某一行的字体变化
- MyBatis学习笔记(四)表字段名与实体类属性名不相同解决
- 高并发的epoll+线程池,业务在线程池内
- IOS 高斯模糊 (毛玻璃效果 UIVisualEffect)
- PHP正则表达式语法汇总
- DeBug调试输出
- git的安装
- Python爬虫进阶一之爬虫框架Scrapy安装配置
- CSS3 垂直树状图——运用 :before 和 :after