• UIPickerView


    一、UIPickerView常用方法

      1、UIPickerView和UIDatePicker是类似的控件,只不过UIDatePicker是日期控件,只能放日期,而UIPickerView可以放任何东西。

      2、UIPickerView例子

      

      3、UIPickerView代理

        @property(nonatomic,assign)

          id<UIPickerViewDelegate> delegate;

        @property(nonatomic,assign)

          id<UIPickerViewDataSource>dataSource;

        delegate 定义了UIPickerView的外观和属性

        dataSource 定义了UIPickerView的数据源和定制内容

      4、UIPickerView常用方法

        1>返回component列,row行的一个UIView,这里只有在定制的情况下才有小,其他情况返回nil

        2>- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;

        3>重新装在整个UIPickerView所有列的数据和指定列的数据

        4>- (void) reloadAlllComponents;

        5>- (void) reloadComponent:(NSInteger)component;

        6>现在UIPickerView中component列,row行,也就是让改行滚动到中央

        7>- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;

        8>返回定制列component中选中的行,没有选中返回-1;

        9>- (NSInteger)selectedRowInComponent:(NSInteger)component;

    二、UIPickerViewDataSource

      1、返回UIPickerView一共有几列

        - (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView;

      2、返回定制的component列有几行数据

        - (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component; 

    三、UIPickerViewDelegate

      1、

        

      2、

         

      3、主要的使用的借个方法的代码如下

        

    View Code
    #pragma mark-
    #pragma mark PickerView function
    
    /*表示UIPickerView一共有几列*/
    - (NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
    {
        return 1;
    }
    /*返回component这列有多少行数据*/
    - (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    {
        return [fonts count];
    }
    /*返回component这列 row这行里面的字符串是什么*/
    - (NSString *) pickerView:(UIPickerView *)pickerView 
                  titleForRow:(NSInteger)row 
                 forComponent:(NSInteger)component
    {
        return [fonts objectAtIndex:row];
    }
    /*当我们选择UIPickerView中列为component,行为row的回调函数*/
    - (void) pickerView:(UIPickerView *)pickerView 
           didSelectRow:(NSInteger)row 
            inComponent:(NSInteger)component
    {
        /*设置字体的样式*/
        NSLog(@"font %d is selected",row);
        NSString *fontName=[fonts objectAtIndex:row];
        fontLabel.font=[UIFont fontWithName:fontName size:20.0f];
        fontLabel.text=[NSString stringWithFormat:@"字体 %@ 选中了",fontName];
    }

    四、定制UIPickerView

      1、

            

      

        

     
     
    分类: IOS
  • 相关阅读:
    文本PDG文件名构成
    关于文本PDG的字体
    Oracle 11G R2 在windows server 2008 64位安装时提示:无法在windows "开始"菜单或桌面上创建项
    GTONE上安装插件无法显示SecurityPrism菜单
    Centos系统下Lamp环境的快速搭建(超详细)
    Windows 10激活
    word如何让单页变横向
    redhat 6.x 上创建用户
    redhat下网络的配置
    Windows 10、Windows 2012 安装 Oracle 11g 报错:[INS-13001]环境不满足最低要求。
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2843702.html
Copyright © 2020-2023  润新知