2016-10-04 92 views
0

我正在使用UIPickerview。我想我的觀點是:如何自定義UIPickerView?

View as needed

但我正在逐漸爲:

View as I am getting

有沒有辦法讓selectionIndicator接近字符串?並隱藏數字,將高於selectionIndicator?

+0

我覺得沒有辦法做到這樣。 Pickerview默認由功能提供,你不能自定義。所以儘可能使用 –

+0

檢查我的answer.it工作正常。 – user3182143

回答

0

lakhan bhojwan嘗試下面的答案。我創建了示例one.It完美的作品。

ViewController.h

#import <UIKit/UIKit.h> 

@interface ViewController : UIViewController<UIPickerViewDelegate,UIPickerViewDataSource> 

@property (strong, nonatomic) IBOutlet UIPickerView *pickerCustom; 

@end 

ViewController.m

#import "ViewController.h" 

@interface ViewController() 
{ 
    NSMutableArray *arrPicker; 
} 

@end 

@implementation ViewController 

@synthesize pickerCustom; 


- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    arrPicker = [[NSMutableArray alloc]initWithObjects:@"Rate this page",@"10",@"9",@"8",@"7",@"6",@"5",@"4",@"3",@"2",@"1",nil];  
    [pickerCustom selectRow:1 inComponent:0 animated:YES]; 
} 


- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 


// The number of columns of data 
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView 
{ 
    return 1; 
} 

// The number of rows of data 
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component 
{ 
    return [arrPicker count]; 
} 

// The data to return for the row and component (column) that's being passed in 
- (NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{ 
    return arrPicker[row]; 
} 

@end 

下面輸出截圖

enter image description here

+0

在這裏,您只是提供基本的pickerview。我希望selectionIndicator接近字符串「爲此頁評分」 –

+0

評價此頁面是標籤還是選擇器視圖數據? – user3182143

+0

顯然這將是一個標籤 –