uiPIcerview的简单应用【1】

//
//  ViewController.m
//  pickview测试
//
//  Created by ibokan on 16/7/14.
//  Copyright © 2016年 ivna. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()< UIPickerViewDelegate , UIPickerViewDataSource >
@property ( strong , nonatomic ) UIPickerView *pickV;
@property ( strong , nonatomic ) NSArray *infoArr;

@end

@implementation ViewController

- (
void )viewDidLoad {
    [
super viewDidLoad ];
   
   
    [
self . view addSubview : self . pickV ];
   
   
// Do any additional setup after loading the view, typically from a nib.
}


#pragma mark-----datasource

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

   
return 1 ;

}
-(
void )pickerView:( UIPickerView *)pickerView didSelectRow:( NSInteger )row inComponent:( NSInteger )component
{
   
NSLog ( @"%@" , self . infoArr [row]);

}



/**
 *
 *
 *  @param pickerView
 *  @param row 行
 *  @param component 第几列
 *
 *  @return 返回当前行的内容
 */

-(
NSString *)pickerView:( UIPickerView *)pickerView titleForRow:( NSInteger )row forComponent:( NSInteger )component
{

   
return   self . infoArr [row];

}
/**
 *
 *
 *  @param pickerView
 *  @param component列
 *
 *  @return 行的宽度
 */

-(
CGFloat )pickerView:( UIPickerView *)pickerView widthForComponent:( NSInteger )component
{
   
return 100 ;
}
// returns the # of rows in each component..
- (
NSInteger )pickerView:( UIPickerView *)pickerView numberOfRowsInComponent:( NSInteger )component
{
//    if (component==0) {
//        return
//    }

   
return self . infoArr . count ;
}
/**
 *
 *
 *  @param pickerView
 *  @param row
 *  @param component
 *  @param view
 *
 *  @return pickv的显示文本
 */

- (
UIView *)pickerView:( UIPickerView *)pickerView viewForRow:( NSInteger )row forComponent:( NSInteger )component reusingView:( UIView *)view{
   
UILabel * pickerLabel = ( UILabel *)view; //强制转换成lab
   
if (!pickerLabel){
        pickerLabel = [[
UILabel alloc ] init ];
   
        pickerLabel.
font = [ UIFont systemFontOfSize : 8.0 ];
        pickerLabel.
adjustsFontSizeToFitWidth = YES ; //让他适应文本的宽度
        [pickerLabel
setTextAlignment : NSTextAlignmentCenter ]; //居中
        [pickerLabel
setBackgroundColor :[ UIColor clearColor ]];
        [pickerLabel
setFont :[ UIFont boldSystemFontOfSize : 15 ]];
             
/**
         1  + systemFontOfSize
         2  + boldSystemFontOfSize
         3  + italicSystemFontOfSize
        
         1 中是系统的默认方法
         2 是字体  bold :醒目的;雄浑的;突出的,使用后会加粗字体
         3 字体为斜体 italic [i'tælik] n. 斜体,斜体字
         */

    }
 
    pickerLabel.
text =[ self pickerView :pickerView titleForRow :row forComponent :component];
   
return pickerLabel;
}
#pragma mark----- get
-( UIPickerView *)pickV
{

   
if (! _pickV ) {
       
_pickV =[[ UIPickerView alloc ] initWithFrame : CGRectMake ( 50 , 100 , 200 , 200 )];
       
_pickV . dataSource = self ;
       
_pickV . delegate = self ;
       
_pickV . showsSelectionIndicator = YES ;
    }
   
return _pickV ;


}
-(
NSArray *)infoArr
{
   
if (! _infoArr ) {
       
_infoArr = @[ @"默认" , @"应届生" , @"1年以内" , @"1-3年" , @"3-5年" , @"5-10年" , @"10年以上" ] ;
    }
   
return _infoArr ;


}

- (
void )didReceiveMemoryWarning {
    [
super didReceiveMemoryWarning ];
   
// Dispose of any resources that can be recreated.
}

@end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值