• UIPickerView选择控件实现选择轮播效果(转轮效果)


    UIPickerView为用户提供了选择器功能,使用户以更好的体验方式实现数据的选择,如图:

    UIPickerView控件的使用方法:(创建好根视图:MainViewController)

     1 #import <UIKit/UIKit.h>  
     2   
     3 @interface MainViewController : UIViewController<UIPickerViewDelegate>  
     4 {  
     5     UIPickerView *pickerView;  
     6     UILabel *contentview;  
     7     NSArray *content;  // 星座;  
     8 }  
     9   
    10 @end  

    实现部分:

     1 - (void)viewDidLoad  
     2 {  
     3     [super viewDidLoad];  
     4     // Do any additional setup after loading the view.  
     5 }  
     6 -(void)loadView  
     7 {  
     8     UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];  
     9     self.view = view;  
    10     view.backgroundColor = [UIColor yellowColor];  
    11     [view release];  
    12     // 初始化数据, 这些数据将显示在picker中  
    13     content = [[NSArray alloc] initWithObjects:@"水瓶座", @"双鱼座", @"白羊座        ", @"金牛座", @"双子座", @"巨蟹座", @"狮子座", @"处女座", @"天秤座", @"天蝎座", @"射手座", @"白羊座",nil];  
    14     // 设置选择器  
    15     pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 150, 320, 216)];  
    16     // 设置代理  
    17     pickerView.delegate = self;  
    18     pickerView.showsSelectionIndicator = YES;  
    19     [self.view addSubview:pickerView];  
    20     contentview = [[UILabel alloc] initWithFrame:CGRectMake(80, 80, 100, 40)];  
    21     contentview.backgroundColor = [UIColor clearColor];  
    22     [self.view addSubview:contentview];  
    23 }  
    24 #pragma mark--处理方法  
    25 // 返回显示的数列  
    26 - (NSInteger)numberOfRowsInComponent:(NSInteger)component  
    27 {  
    28     return 1;  
    29 }  
    30 // 返回当前列显示的行数  
    31 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component  
    32 {  
    33     return [content count];  
    34 }  
    35 // 设置当前的内容,如果行没有显示则自动释放  
    36 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component  
    37 {  
    38     return [content objectAtIndex:row];  
    39 }  
    40 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component  
    41 {  
    42 //    NSString *result = [pickerView pickView:pickerView titleForRow:row forComponent:component];  
    43       
    44     NSString *result = nil;  
    45     result = [content objectAtIndex:row];  
    46     NSLog(@"result:%@", result);  
    47     contentview.text = result;  
    48     [result release];  
    49 }  
    50 - (void)didReceiveMemoryWarning  
    51 {  
    52     [super didReceiveMemoryWarning];  
    53     // Dispose of any resources that can be recreated.  
    54 }  
    有人说:爱上一座城,是因为城里住着某个人,能够与所爱的人在一起,连光阴都是美的。即便粗茶淡饭,修篱种田,只要有你陪伴就好。那么,找一个青山绿水的地方,寻一处幽静的茅舍,或是云水禅心的庭院,那里有晴朗的阳光和静谧的悠然,还有你明媚的笑脸。掬一捧花香在平淡的日子,握着一路相随的暖意,让爱的馨香在柴米油盐中升腾;在一杯茶的温情里,体味生活的诗意;在一碗粥的清淡中,感受生活的浪漫,每天清晨你和阳光都在,便是我的幸福。——春暖花开 《择一城终老,遇一人白首》
  • 相关阅读:
    如何进行shell脚本正确性测试
    linux 重命名文件和文件夹
    linux 下 `dirname $0`
    五句话搞定JavaScript作用域
    Javascrpt
    css
    HTML
    python之sqlalchemy
    Python之路【第九篇】:Python操作 RabbitMQ、Redis、Memcache、SQLAlchemy
    Python之路【第八篇】:堡垒机实例以及数据库操作
  • 原文地址:https://www.cnblogs.com/-Eric-Liu/p/5564046.html
Copyright © 2020-2023  润新知