• UIpickerView





    #import
    "DengViewController.h" @interface DengViewController () @end @implementation DengViewController - (void)viewDidLoad { [super viewDidLoad]; CGRect rect=CGRectMake(0, 0,320, 220); _showlabel=[[UILabel alloc] initWithFrame:rect]; _showlabel.backgroundColor=[UIColor grayColor]; _showlabel.textAlignment=NSTextAlignmentCenter; _showlabel.font=[UIFont systemFontOfSize:18]; [self.view addSubview:_showlabel]; UIPickerView *pickerview = [[UIPickerView alloc] init]; CGRect fram =pickerview.frame; fram.origin.y=self.view.bounds.size.height-fram.size.height; pickerview.frame=fram; pickerview.showsSelectionIndicator=YES; pickerview.backgroundColor=[UIColor yellowColor]; pickerview.delegate=self; pickerview.dataSource=self; [self.view addSubview:pickerview]; [pickerview reloadAllComponents]; [self pickerView:pickerview didSelectRow:0 inComponent:0]; // Do any additional setup after loading the view, typically from a nib. } - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{ return 2; } - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ return 9; } - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{ return 30; } - (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{ return 80; } - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{ if (view==nil) { CGFloat width = [self pickerView:pickerView widthForComponent:component]; CGFloat heigh = [self pickerView:pickerView rowHeightForComponent:row]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, heigh)]; label.textAlignment=NSTextAlignmentCenter; label.font=[UIFont systemFontOfSize:16]; view=label; } UILabel *label =(UILabel*)view; label.text=[NSString stringWithFormat:@"%d",row+1]; if (row%2!=1) { label.backgroundColor=[UIColor redColor]; } return label; } - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{ NSInteger row0 =[pickerView selectedRowInComponent:0]; NSInteger row1 =[pickerView selectedRowInComponent:1]; UILabel *label1=(UILabel *)[pickerView viewForRow:row0 forComponent:0]; UILabel *label2=(UILabel *)[pickerView viewForRow:row1 forComponent:1]; int result =label1.text.intValue*label2.text.intValue; _showlabel.text=[NSString stringWithFormat:@"%d",result]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
  • 相关阅读:
    [HAOI2012]高速公路(BZOJ2752)
    [SHOI2008]堵塞的交通traffic(BZOJ1018)
    AHOI2009 行星序列Seq (BZOJ1798)
    java注解问题
    回调方法举例
    log4j将日志文件保存到项目中
    ehCache+springMVC的简单实用
    MyBatis排序时使用order by 动态参数时需要注意,用$而不是#
    mybatis配置log4j
    mybatis ---- 分页 (拦截器)
  • 原文地址:https://www.cnblogs.com/deng37s/p/4583475.html
Copyright © 2020-2023  润新知