如何在ios的UIPICKER VIEW中禁用滚动效果和阴影效果?

时间:2014-02-27 11:39:07

标签: ios ios7

我正在开发 UIPICKERVIEW 的一个例子,我想禁用或关闭 阴影效果滚动效果但不能做到。你对此有什么想法吗?

源代码: pickerViewController.h文件

#import <UIKit/UIKit.h>

@interface pickerViewController : UIViewController<UIPickerViewDataSource,UIPickerViewDelegate>
{
    UIPickerView *languageSelect;
    NSMutableArray *pickerData;
}
@property (nonatomic, retain) UIPickerView *languageSelect;
@property (nonatomic, retain)  NSArray *pickerData;
@end

pickerViewController.m文件

#import "pickerViewController.h"

@interface pickerViewController ()

@end

@implementation pickerViewController
@synthesize languageSelect, pickerData;
- (void)viewDidLoad
{
    [super viewDidLoad];
    pickerData= [[NSMutableArray alloc]     initWithObjects:@"English",@"Spanish",@"French",@"Greek",
             @"Japaneese",@"Korean",@"Hindi",@"English",@"Spanish",@"French",@"Greek",
             @"Japaneese",@"Korean",@"Hindi", nil];

    languageSelect = [[UIPickerView alloc] initWithFrame:CGRectMake(10, 50, 300, 1000)];
    languageSelect.showsSelectionIndicator = YES;
    languageSelect.hidden = NO;
    languageSelect.delegate = self;
    [self.view addSubview:languageSelect];

}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView; {
    return 1;
}

    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:   (NSInteger)component; 
{
    return [pickerData count];
}
    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {

UILabel *pickerLabel = (UILabel *)view;

    NSString* labelText = [NSString stringWithFormat:@"%@",[pickerData objectAtIndex:row]];

if (pickerLabel == nil) {
    CGSize size = [labelText sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:CGSizeMake(250, 216) lineBreakMode:NSLineBreakByCharWrapping];
    CGRect frame = CGRectMake(0.0, 0.0, 250, size.height + 25);
    pickerLabel = [[UILabel alloc] initWithFrame:frame];
    [pickerLabel setTextAlignment:NSTextAlignmentLeft];
    [pickerLabel setBackgroundColor:[UIColor clearColor]];
    [pickerLabel setFont:[UIFont boldSystemFontOfSize:15]];
    [pickerLabel setLineBreakMode:NSLineBreakByWordWrapping];

        // trying to mess with the UIView of the row itself... to no avail
    //CGRect rowFrame = view.frame;
    //NSLog(@"%f",rowFrame.size.height);
    //rowFrame.size.height = size.height + 25;
    //view.frame = rowFrame;
}

[pickerLabel setText:[pickerData objectAtIndex:row]];

//NSLog(@"%f",[pickerView rowSizeForComponent:component].height);

return pickerLabel;
}

-(NSString*) pickerView:(UIPickerView*)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [pickerData objectAtIndex:row];
}

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

}

输出:

enter image description here

我想做这样的事情...... !!

enter image description here

2 个答案:

答案 0 :(得分:2)

这是很多自定义工作。如果你想实现这种外观,你最好尝试使用UITableView。你仍然需要付出相当大的努力。

答案 1 :(得分:0)

  

在pic中你可以看到UIPickerView的结构。   http://i.stack.imgur.com/QFAKV.png

enter image description here

  

也许删除一些图层可以帮助您   http://i.stack.imgur.com/C2xDO.png

enter image description here