UIpickerView

//
//  UIpickerViewController.m
//  AppUI组件学习
//
//  Created by 麦子 on 15/6/18.
//  Copyright (c) 2015年 麦子. All rights reserved.
//

#import "UIpickerViewController.h"

@interface UIpickerViewController (){

    UILabel *label;
    UIFont *font;
    NSArray *array;
}

@end

@implementation UIpickerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blackColor];
    [self createView:self.view];
}

- (void)createView:(id)uiView{
    UIView *view = (UIView *)uiView;
    
    label = [[UILabel alloc] init];
    label.frame = CGRectMake(20, 80, 300, 80);
    label.backgroundColor = [UIColor whiteColor];
    label.textAlignment = NSTextAlignmentCenter;
    label.text = @"请选中你需要的字体";
    
    
    UIPickerView  *picker = [[UIPickerView alloc] init];
    picker.frame = CGRectMake(20, 200, 300, 100);
    picker.backgroundColor = [UIColor orangeColor];
    
    array = [UIFont familyNames];
    picker.delegate = self;
    picker.dataSource = self;
    
    [view addSubview:picker];
    [view addSubview:label];
    
}

#pragma mark - 
#pragma mark PickerView function
/***表示UIPickerVIew一共有几列**/
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

    return 1;
}

/***返回component这一列有多少行数据**/
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

    return [array count];
}

/*返回component列中的row行的里面的字符串**/
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{


    return [array objectAtIndex:row];
}

/**选中,component列,row行的时候的回调的方法**/
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
   
    NSString *fontName = [array objectAtIndex:row];
    label.font = [UIFont fontWithName:fontName size:20.0f];
    label.text = [NSString stringWithFormat:@"字体%@被选中了",fontName];

}





@end

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值