UIPickerView选择控件实现选择轮播效果(转轮效果)
来源:互联网 发布:安卓系统数据网络开关 编辑:程序博客网 时间:2024/04/29 08:19
UIPickerView为用户提供了选择器功能,使用户以更好的体验方式实现数据的选择,如图:
UIPickerView控件的使用方法:(创建好根视图:MainViewController)
#import <UIKit/UIKit.h>@interface MainViewController : UIViewController<UIPickerViewDelegate>{ UIPickerView *pickerView; UILabel *contentview; NSArray *content; // 星座;}@end
实现部分:
- (void)viewDidLoad{ [super viewDidLoad]; // Do any additional setup after loading the view.}-(void)loadView{ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)]; self.view = view; view.backgroundColor = [UIColor yellowColor]; [view release]; // 初始化数据, 这些数据将显示在picker中 content = [[NSArray alloc] initWithObjects:@"水瓶座", @"双鱼座", @"白羊座 ", @"金牛座", @"双子座", @"巨蟹座", @"狮子座", @"处女座", @"天秤座", @"天蝎座", @"射手座", @"白羊座",nil]; // 设置选择器 pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 150, 320, 216)]; // 设置代理 pickerView.delegate = self; pickerView.showsSelectionIndicator = YES; [self.view addSubview:pickerView]; contentview = [[UILabel alloc] initWithFrame:CGRectMake(80, 80, 100, 40)]; contentview.backgroundColor = [UIColor clearColor]; [self.view addSubview:contentview];}#pragma mark--处理方法// 返回显示的数列- (NSInteger)numberOfRowsInComponent:(NSInteger)component{ return 1;}// 返回当前列显示的行数- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{ return [content count];}// 设置当前的内容,如果行没有显示则自动释放- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{ return [content objectAtIndex:row];}- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{// NSString *result = [pickerView pickView:pickerView titleForRow:row forComponent:component]; NSString *result = nil; result = [content objectAtIndex:row]; NSLog(@"result:%@", result); contentview.text = result; [result release];}- (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}
0 0
- UIPickerView选择控件实现选择轮播效果(转轮效果)
- UIPickerView实现效果
- jquery实现菜单栏选择效果
- UIPickerView(选择框)
- 实现TreeGrid中复选框的级联选择效果(类似zTree的选择效果)
- 自定义时间选择控件(仿ios滚动效果)
- UIScrollView实现轮播效果
- 轮播广告效果实现
- js实现轮播效果
- jQuery实现轮播效果
- banner实现轮播效果
- Android自定义控件实现多行文字自动向上滚动轮播效果(伪文字轮播)
- JavaScript案例——图片的轮播效果、动态生成表格、下拉框左右选择以及动画效果
- iOS自定义UICollectionViewlayout仿英雄联盟选择皮肤立体轮播效果展示
- IOS UIPickerView控件的关联选择
- 数据选择控件-UIPickerView的总结
- 自定义View实现SeekBar点值选择效果(一)
- 自定义View实现点值选择效果(二)
- 跳槽指南(4) - 如何选择公司
- LeetCode: Reverse Words in a String
- Makefile学习
- 屏幕适配问题
- Builder(生成器模式)
- UIPickerView选择控件实现选择轮播效果(转轮效果)
- The reference to entity "characterEncoding" must end with the ';' delimiter
- 解决android虚拟机不能打开的问题
- struts异常自动处理机制
- SQL Server 2008 转换为 SQL 2005 数据库 脚本生成
- POJ2192(最长公共子序列)
- iOS中添加UITapGestureRecognizer手势识别后,UITableView的didSelectRowAtIndexPath失效
- Linux - error: Failed dependencies:
- python中文转换url编码