Iphone 水平实现UIPickerView?

Iphone 水平实现UIPickerView?,iphone,xcode,uipickerview,Iphone,Xcode,Uipickerview,UIPickerView的默认滚动设置设置为垂直。是否可以水平实施UIPickerView 如果是这样的话,你能给我看一个样品或者告诉我在哪里可以找到有用的文档吗?你可以使用。。UIPickerView的自定义、可配置的水平版本(基于旋转的轮子或老虎机隐喻),包含一个表单元实现。最初用于压缩多选项设置所需的空间/行。在.h文件中 #import <UIKit/UIKit.h> @interface ViewController : UIViewController <UIPi

UIPickerView
的默认滚动设置设置为垂直。是否可以水平实施
UIPickerView


如果是这样的话,你能给我看一个样品或者告诉我在哪里可以找到有用的文档吗?

你可以使用。。UIPickerView的自定义、可配置的水平版本(基于旋转的轮子或老虎机隐喻),包含一个表单元实现。最初用于压缩多选项设置所需的空间/行。

在.h文件中

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIPickerViewDelegate> {
    IBOutlet UIPickerView *pickerView;
    NSMutableArray *itemArray;
    IBOutlet UILabel *myLabel;
}

@property (nonatomic, retain)  UIPickerView *pickerView;
@property (nonatomic, retain)  UILabel *myLabel;

@end  
#import "ViewController.h"

@implementation ViewController

@synthesize pickerView, myLabel;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

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

    self.pickerView.delegate = self;
    self.pickerView.showsSelectionIndicator =YES;
    self.pickerView.backgroundColor = [UIColor blackColor];

    CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI_2);
    rotate = CGAffineTransformScale(rotate, 0.1, 0.8);
    [self.pickerView setTransform:rotate];  

    self.pickerView.center = CGPointMake(160,75);


    UILabel *theview[20]; 
    CGAffineTransform rotateItem = CGAffineTransformMakeRotation(-M_PI_2);
    rotateItem = CGAffineTransformScale(rotateItem, 1, 10);

    for (int i=0;i<20;i++) {  
        theview[i] = [[UILabel alloc] init];
        theview[i].text = [NSString stringWithFormat:@"%d",i];
        theview[i].textColor = [UIColor blackColor];
        theview[i].frame = CGRectMake(0,0, 100, 100);
        theview[i].backgroundColor = [UIColor clearColor];
        theview[i].textAlignment = NSTextAlignmentCenter; //UITextAlignmentCenter is deprecated.
        theview[i].shadowColor = [UIColor whiteColor];
        theview[i].shadowOffset = CGSizeMake(-1,-1);
        theview[i].adjustsFontSizeToFitWidth = YES;

        UIFont *myFont = [UIFont fontWithName:@"Georgia" size:15];
        [theview[i] setFont:myFont];

        theview[i].transform = rotateItem;
    }





    itemArray = [[NSMutableArray alloc] init];

    for (int j=0;j<20;j++) { 

        [itemArray addObject:theview[j]];

    }

}


#pragma mark -
#pragma mark Picker View Methods

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

    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {

    return [itemArray count];
}



- (UIView *)pickerView:(UIPickerView *)thePickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{

    return [itemArray objectAtIndex:row];

}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    myLabel.text = [NSString stringWithFormat:@"SELECTED: %d", row+1];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
#导入
@界面ViewController:UIViewController{
IBUIPickerView*pickerView;
NSMutableArray*项目数组;
IBUILabel*myLabel;
}
@属性(非原子,保留)UIPickerView*pickerView;
@属性(非原子,保留)UILabel*myLabel;
@结束
.XIB文件中的

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIPickerViewDelegate> {
    IBOutlet UIPickerView *pickerView;
    NSMutableArray *itemArray;
    IBOutlet UILabel *myLabel;
}

@property (nonatomic, retain)  UIPickerView *pickerView;
@property (nonatomic, retain)  UILabel *myLabel;

@end  
#import "ViewController.h"

@implementation ViewController

@synthesize pickerView, myLabel;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

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

    self.pickerView.delegate = self;
    self.pickerView.showsSelectionIndicator =YES;
    self.pickerView.backgroundColor = [UIColor blackColor];

    CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI_2);
    rotate = CGAffineTransformScale(rotate, 0.1, 0.8);
    [self.pickerView setTransform:rotate];  

    self.pickerView.center = CGPointMake(160,75);


    UILabel *theview[20]; 
    CGAffineTransform rotateItem = CGAffineTransformMakeRotation(-M_PI_2);
    rotateItem = CGAffineTransformScale(rotateItem, 1, 10);

    for (int i=0;i<20;i++) {  
        theview[i] = [[UILabel alloc] init];
        theview[i].text = [NSString stringWithFormat:@"%d",i];
        theview[i].textColor = [UIColor blackColor];
        theview[i].frame = CGRectMake(0,0, 100, 100);
        theview[i].backgroundColor = [UIColor clearColor];
        theview[i].textAlignment = NSTextAlignmentCenter; //UITextAlignmentCenter is deprecated.
        theview[i].shadowColor = [UIColor whiteColor];
        theview[i].shadowOffset = CGSizeMake(-1,-1);
        theview[i].adjustsFontSizeToFitWidth = YES;

        UIFont *myFont = [UIFont fontWithName:@"Georgia" size:15];
        [theview[i] setFont:myFont];

        theview[i].transform = rotateItem;
    }





    itemArray = [[NSMutableArray alloc] init];

    for (int j=0;j<20;j++) { 

        [itemArray addObject:theview[j]];

    }

}


#pragma mark -
#pragma mark Picker View Methods

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

    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {

    return [itemArray count];
}



- (UIView *)pickerView:(UIPickerView *)thePickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{

    return [itemArray objectAtIndex:row];

}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    myLabel.text = [NSString stringWithFormat:@"SELECTED: %d", row+1];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
拖放UIPickerView和一个UILable 还要将“委托”和“引用出口”连接到文件所有者

在.M文件中

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIPickerViewDelegate> {
    IBOutlet UIPickerView *pickerView;
    NSMutableArray *itemArray;
    IBOutlet UILabel *myLabel;
}

@property (nonatomic, retain)  UIPickerView *pickerView;
@property (nonatomic, retain)  UILabel *myLabel;

@end  
#import "ViewController.h"

@implementation ViewController

@synthesize pickerView, myLabel;

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

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

    self.pickerView.delegate = self;
    self.pickerView.showsSelectionIndicator =YES;
    self.pickerView.backgroundColor = [UIColor blackColor];

    CGAffineTransform rotate = CGAffineTransformMakeRotation(M_PI_2);
    rotate = CGAffineTransformScale(rotate, 0.1, 0.8);
    [self.pickerView setTransform:rotate];  

    self.pickerView.center = CGPointMake(160,75);


    UILabel *theview[20]; 
    CGAffineTransform rotateItem = CGAffineTransformMakeRotation(-M_PI_2);
    rotateItem = CGAffineTransformScale(rotateItem, 1, 10);

    for (int i=0;i<20;i++) {  
        theview[i] = [[UILabel alloc] init];
        theview[i].text = [NSString stringWithFormat:@"%d",i];
        theview[i].textColor = [UIColor blackColor];
        theview[i].frame = CGRectMake(0,0, 100, 100);
        theview[i].backgroundColor = [UIColor clearColor];
        theview[i].textAlignment = NSTextAlignmentCenter; //UITextAlignmentCenter is deprecated.
        theview[i].shadowColor = [UIColor whiteColor];
        theview[i].shadowOffset = CGSizeMake(-1,-1);
        theview[i].adjustsFontSizeToFitWidth = YES;

        UIFont *myFont = [UIFont fontWithName:@"Georgia" size:15];
        [theview[i] setFont:myFont];

        theview[i].transform = rotateItem;
    }





    itemArray = [[NSMutableArray alloc] init];

    for (int j=0;j<20;j++) { 

        [itemArray addObject:theview[j]];

    }

}


#pragma mark -
#pragma mark Picker View Methods

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

    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {

    return [itemArray count];
}



- (UIView *)pickerView:(UIPickerView *)thePickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{

    return [itemArray objectAtIndex:row];

}

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    myLabel.text = [NSString stringWithFormat:@"SELECTED: %d", row+1];
}


- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
#导入“ViewController.h”
@实现视图控制器
@合成pickerView,myLabel;
-(无效)未收到记忆警告
{
[超级记忆警告];
//释放所有未使用的缓存数据、图像等。
}
#pragma标记-视图生命周期
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
self.pickerView.delegate=self;
self.pickerView.showselectionindicator=YES;
self.pickerView.backgroundColor=[UIColor blackColor];
CGAffineTransform rotate=CGAffineTransformMakeRotation(M_PI_2);
旋转=CGAffineTransformScale(旋转,0.1,0.8);
[self.pickerView setTransform:rotate];
self.pickerView.center=CGPointMake(160,75);
UILabel*视图[20];
CGAffineTransform rotateItem=CGAffineTransformMakeRotation(-M_PI_2);
rotateItem=CGAffineTransformScale(rotateItem,1,10);

对于(int i=0;我尝试了什么来实现这一点?请查看以下内容: