//
// ViewController.m
// UIPickerViewBySelf
//
// Created by MAC on 13-1-29.
// Copyright (c) 2013年 MAC. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize fontlabel;
@synthesize pickView;
- (void)viewDidLoad
{
[super viewDidLoad];
self.pickView.dataSource = self;
self.pickView.delegate = self;
fonts = [UIFont familyNames];
fontSize = [NSArray arrayWithObjects:@"10",@"15",
@"20",@"25",
@"30",@"35",
@"40",@"45", nil];
fontColor =[NSArray arrayWithObjects:
[UIColor redColor],
[UIColor blueColor],
[UIColor blackColor],
[UIColor yellowColor],
[UIColor grayColor],
[UIColor greenColor],
[UIColor brownColor],
[UIColor orangeColor],
[UIColor purpleColor],
[UIColor magentaColor],nil];
for(int i= 0;i<3;i++)
{
int row = 0;
if(i==0)
{
row = [fonts count]/2;
}
else if (i==1)
{
row = [fontColor count]/2;
}
else if (i==2)
{
row =[fontSize count]/2;
}
[pickView selectRow:row inComponent:i animated:true];
}
// [fontColor retain];
// Do any additional setup after loading the view, typically from a nib.
}
-(void) pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
UIView *view0,*view1,*view2;
NSInteger row0,row1,row2;
row0 = [pickView selectedRowInComponent:0];
row1 = [pickView selectedRowInComponent:1];
row2 = [pickView selectedRowInComponent:2];
view0 = [pickView viewForRow:row0 forComponent:0];
view1 = [pickView viewForRow:row1 forComponent:1];
view2 = [pickView viewForRow:row2 forComponent:2];
UILabel *label1,*label2,*label0;
label0 =(UILabel *)[view0 viewWithTag:200];
label1 =(UILabel *)[view1 viewWithTag:200];
label2 =(UILabel *)[view2 viewWithTag:200];
fontlabel.font = [UIFont fontWithName:label0.text size:[label2.text floatValue]];
fontlabel.textColor = label1.backgroundColor;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark -
#pragma mark UIPICKVIEW CUSTOM FUNTION
//返回一共几列的值
-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 3;
}
//返回每列具体多少行
-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if(component==0)
{
return [fonts count];}
else if(component==1)
{
return [fontColor count];
}
else if(component ==2)
{
return [fontSize count];
}
return -1;
}
//返回三列各列宽度
-(CGFloat) pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
if(component==0)
{
return 180.0f;}
else if(component==1)
{
return 90.0f;
}
else if(component ==2)
{
return 50.0f;
}
return 0.0f;
}
//返回row高度
-(CGFloat) pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return 50.0f;
}
//可以理解为自定义的view内容
-(UIView *) pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
CGFloat width = [self pickerView:pickView widthForComponent:component];
CGFloat rowheight =[self pickerView:pickView rowHeightForComponent:(component)];
UIView *myView = [[UIView alloc]init];
myView.frame =CGRectMake(0.0f, 0.0f, width, rowheight);
UILabel *txtlabel = [[UILabel alloc] init];
txtlabel.tag=200;
txtlabel.frame = myView.frame;
[myView addSubview:txtlabel];
if(component==0)
{
txtlabel.text = [fonts objectAtIndex:row];
}
else if(component==1)
{
txtlabel.backgroundColor =[fontColor objectAtIndex:row];
}
else if(component==2)
{
txtlabel.text =[fontSize objectAtIndex:row];
}
return myView;
}
@end
分享到:
相关推荐
自定义pickView效果
BAPickView 最为精简的 自定义 pickView 和 日期选择器 封装
闲得蛋疼,自定义一个pickView玩玩,挺好用的
简单实现自定义checkbox控件四种选择状态的图片样式
一个简单的自定义的pickView根据不同选择,显示不同数据
自定义adapter checkbox选中处理,处理多选问题
自定义RecyclerView实现画廊效果自定义RecyclerView实现画廊效果自定义RecyclerView实现画廊效果
自定义选框,选中之后边框变红,比较灵活多变,可以在此基础上衍变成自己喜欢的模式,可以应用到正式的项目里,希望大家能喜欢
qt自定义图形实现拖拽效果.7z
自定义 PickerView 选中行下划线
这个是ExpandableListView的样式改造小demo,去掉箭头等控制,自定义选中时的效果及子View选中时的效果。
自定义ScrollView实现阻尼效果+控件悬浮
javascript九种自定义弹出层效果
自定义 UIView的阴影效果自定义 UIView的阴影效果
仿真书籍翻页效果BookPageView简介:实现了仿真翻页效果,教程完整地描述了翻页原理分析到性能优化的过程教程博客:Android自定义View——从零开始实现书籍翻页效果(一) Android自定义View——从零开始实现书籍...
本文实例为大家分享了Qt自定义图形实现拖拽效果的具体代码,供大家参考,具体内容如下 在这里自定义图形是通过QPaintEvent事件绘画的图形,也可以通过自定义控件的方式添加到qt中。 首先定义类来自定义图形,这里...
安卓自定义View,实现点赞爆炸效果,里面有酷炫的动画!
TextView + 背景设置, 产生自定义Tab选中效果
自定义鼠标滚轮的效果 4个demo 希望对大家有用啊
在PowerPoint2021中创建自定义动画效果.docx