修改UIPickerView选中⾏的⽂字⼤⼩和颜⾊直接粘贴代码
#import "ViewController.h"
@interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@interface
IBOutlet UIPickerView *pickerView;
nonatomic) IBOutlet
strong, nonatomic
@property (strong
nonatomic,strong
strong)NSMutableArray *hArr;
@property(nonatomic
strong)NSMutableArray *mArr;
nonatomic,strong
@property(nonatomic
@end
@implementation ViewController
- (void
void)viewDidLoad {
super viewDidLoad];
[super
self.hArr);
NSLog(@"%@",self
self.mArr);
NSLog(@"===%@",self
self.view.bounds.size.width-50, 80)]; _pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(25, 35, self
_pickerView.backgroundColor = [UIColor clearColor];
_pickerView.delegate = self
self;
self;
_pickerView.dataSource = self
_pickerView.delegate = self
self;
self;
_pickerView.dataSource = self
self.pickerView];
[self
self.view addSubview:self
// Do any additional setup after loading the view.
}
pickerviewDelegate
#pragma mark pickerviewDelegate
//返回列数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return2;
return
}
//返回每列⾏数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if if(component==0) {
return 24;
return
}else
else{mutable是什么意思
return 60;
return
}
}
// 返回每⼀⾏的标题
-(NSString*)pickerView:(UIPickerView*)pickerViewtitleForRow:(NSInteger)rowforComponent:(NSInteger)component
{
if if(component ==0)
{
self.hArr[row];
return self
return
else
}else
{
self.mArr[row];
return self
return
}
}
//改变选中那⾏的字体和颜⾊
- (UIView*)pickerView:(UIPickerView*)pickerViewviewForRow:(NSInteger)rowforComponent:(NSInteger)componentreusingView: (UIView*)view{
if if(!view){
view = [[UIViewalloc]init];
}
self.view.bounds.size.width-50)/3, 20)];
UILabel *text = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, (self
if if(component ==2) {
NSIntegerselecrDay = [_pickerViewselectedRowInComponent:component];
if if(selecrDay == row) {
}
}
if if(component==0) {
<= [_hArrobjectAtIndex:row];
}
if if(component==1) {
<= [_mArrobjectAtIndex:row];
}
[viewaddSubview:text];
return view;
return
}
/
//被选择的⾏
void)pickerView:(UIPickerView*)pickerViewdidSelectRow:(NSInteger)rowinComponent:(NSInteger)component{ -(void
UIView* view = [pickerViewviewForRow:rowforComponent:component];
UILabel* label = view.subviews.firstObject;
label.font = [UIFont systemFontOfSize:30.0];
}
#pragma mark- 懒加载
- 懒加载
-(NSMutableArray *)mArr{
if if(!_mArr){
_mArr= [NSMutableArrayarray];
int i =0; i<60; i++) {
for
for(int
NSString*Str= [NSStringstringWithFormat:@"%02d",i];
[_mArraddObject:Str];
}
}
return
return_mArr;
}
-
(NSMutableArray *)hArr{
if if(!_hArr){
_hArr= [NSMutableArrayarray];
int i =0; i<24; i++) {
for
for(int
NSString*Str= [NSStringstringWithFormat:@"%02d",i];
[_hArraddObject:Str];
}
}
return_hArr;
return
}
@end
主要代码
//改变选中那⾏的字体和颜⾊
- (UIView*)pickerView:(UIPickerView*)pickerViewviewForRow:(NSInteger)rowforComponent:(NSInteger)componentreusingView: (UIView*)view{
if if(!view){
view = [[UIViewalloc]init];
}
self.view.bounds.size.width-50)/3, 20)];
UILabel *text = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, (self
if if(component ==2) {
NSIntegerselecrDay = [_pickerViewselectedRowInComponent:component];
if if(selecrDay == row) {
}
}
if if(component==0) {
<= [_hArrobjectAtIndex:row];
}
if if(component==1) {
<= [_mArrobjectAtIndex:row];
}
[viewaddSubview:text];
return view;
return
}
///被选择的⾏
void)pickerView:(UIPickerView*)pickerViewdidSelectRow:(NSInteger)rowinComponent:(NSInteger)component{ -(void
UIView* view = [pickerViewviewForRow:rowforComponent:component];
UILabel* label = view.subviews.firstObject;
label.font = [UIFont systemFontOfSize:30.0];
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论