博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIpickerView
阅读量:6311 次
发布时间:2019-06-22

本文共 2820 字,大约阅读时间需要 9 分钟。

#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

 

转载于:https://www.cnblogs.com/deng37s/p/4583475.html

你可能感兴趣的文章
xdebug影响php运行速度
查看>>
使用NSHashTable存储引用对象
查看>>
数据库重构《Refactoring DataBase Evolutionary DataBase Design》介绍
查看>>
Java类锁和对象锁实践
查看>>
深入理解Java内存模型(七)——总结
查看>>
根据先序中序遍历建树【模板】
查看>>
linux服务搭建----ftp与ftp yum源搭建
查看>>
[华为机试练习题]57.对象管理器
查看>>
hdu 5422 Rikka with Graph
查看>>
哈夫曼树
查看>>
一分钟了解阿里云产品:加密服务
查看>>
WCF 内存入口检查失败 Memory gates checking failed
查看>>
《C#编程风格》还记得多少
查看>>
gitSource 自定义脚本
查看>>
UISearchController 定制UI(Swift)
查看>>
【干货】模拟js的new
查看>>
从0到1搭建和部署个人博客
查看>>
MySQL命令
查看>>
每个时代都是最坏的时代? | 摸鱼系列
查看>>
面试总结(一)
查看>>