How can we change the size of the text in a picker view?
Anyone please help.
You can change the font size of UIPickerView using code :
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *retval = (id)view;
if (!retval) {
retval= [[[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, [pickerView rowSizeForComponent:component].width, [pickerView rowSizeForComponent:component].height)] autorelease];
}
retval.font = [UIFont systemFontOfSize:22];
return retval;
}
For completeness, yakub_moriss code lacks of one line, which was in the post signaled by indragie. Without a line as
retval.text = [pickerViewArray objectAtIndex:row];
the picker will be empty.
This is also a great way to change the alignment of the text in the component too, change the textAlignment of the retval label.
Also, the background for the label should be set to clear:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *retval = (id)view;
if (!retval) {
retval = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f,
[pickerView rowSizeForComponent:component].width,
[pickerView rowSizeForComponent:component].height)];
}
retval.opaque = NO;
retval.backgroundColor = [UIColor clearColor];
retval.font = [UIFont systemFontOfSize:28];
if (component == 0) {
retval.textAlignment = UITextAlignmentRight;
retval.text = [NSString stringWithFormat:#"%d ", row];
} else {
retval.textAlignment = UITextAlignmentLeft;
retval.text = [NSString stringWithFormat:#" .%d", row];
}
return retval;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
{
if (component == 0) {
return 100;
}
return 88;
}
I'm using a category for this. It relies on this other category I have: http://compileyouidontevenknowyou.blogspot.com/2012/06/adding-properties-to-class-you-dont.html.
Anyway, this one looks like this:
#import <UIKit/UIKit.h>
#interface UIPickerView (CustomViewForRow)
#property (nonatomic, strong) UIFont *customViewForRowFont;
- (UIView *)customViewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
#end
and the .m
#import "UIPickerView+CustomViewForRow.h"
#import "NSObject+AssociatedObjectSupport.h"
#implementation UIPickerView (CustomViewForRow)
static char keyForCustomViewForRowFont;
- (UIFont *)customViewForRowFont {
UIFont *retVal = [self associatedObject:&keyForCustomViewForRowFont];
if (!retVal)
retVal = [UIFont boldSystemFontOfSize:17];
return retVal;
}
- (void)setCustomViewForRowFont:(UIFont *)customViewForRowFont {
[self setAssociatedObject:customViewForRowFont forKey:&keyForCustomViewForRowFont];
}
- (UIView *)customViewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
UILabel *label;
if (!view) {
view = [[UIView alloc] init];
CGRect frame = CGRectZero;
frame.size = [self rowSizeForComponent:component];
view.frame = frame;
view.backgroundColor = UIColor.clearColor;
label = [[UILabel alloc] init];
label.font = self.customViewForRowFont;
label.backgroundColor = [UIColor clearColor];
frame = view.bounds;
frame.origin.x += 7;
frame.size.width -= 14;
label.frame = frame;
[view addSubview:label];
}
label = [view.subviews objectAtIndex:0];
#try {
NSString *text = [self.delegate pickerView:self titleForRow:row forComponent:component];
if (!text)
text = #"???";
label.text = text;
} #catch (NSException *e) {
label.text = #"???";
}
return view;
}
#end
Try this
https://github.com/kafejo/CCPicker
it's very easy picker :)
Related
I need to set the alignment of the text in picker view but my solutions doesn't work.
This is my code so far. I used array to store values on the picker view.
- (void)viewDidLoad{
[super viewDidLoad];
self.source = [[NSMutableArray alloc]
initWithObjects:#" 5 Minutes", #"10 Minutes", #"15 Minutes", #"20 Minutes",#"25 Minutes",#"30 Minutes",#"35 Minutes",#"40 Minutes",#"45 Minutes",#"50 Minutes",#"55 Minutes",#"60 Minutes", nil];
self.picker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 275.0, 320.0, 120.0)];
self.picker.delegate = self;
self.picker.dataSource = self;
[self.view addSubview:self.picker];
[self.picker selectRow:2 inComponent:0 animated:YES];}
then,
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [source objectAtIndex:row];
}
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return [source count];
}
However, it works fine when it displays the values. But when I align the text at the center, instead of displaying the text(values on picker view), the picker view becomes empty. This is the code on how I've done the alignment at the center.
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component
reusingView:(UIView *)view
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 37)];
//label.text = [NSString stringWithFormat:#"something here"];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
return label;
}
What might be the solution for this?
Please help me regarding this problem.
Thanks.
i done with this code for UIlabel text show in center of tableView like:-
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 37)];
if (component == 0) {
label.font=[UIFont boldSystemFontOfSize:22];
label.textAlignment = UITextAlignmentCenter;
label.backgroundColor = [UIColor clearColor];
label.text = [NSString stringWithFormat:#"%#", [source objectAtIndex:row]];
label.font=[UIFont boldSystemFontOfSize:22];
}
[label autorelease];
return label;
}
Code output is
For swift 3 we can use
label.textAlignment = NSTextAlignment.center
use this code instead of your code..
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UIView *viewTemp = [[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 44)]autorelease];
[viewTemp setBackgroundColor:[UIColor clearColor]];
UILabel *lbl = [[[UILabel alloc]initWithFrame:CGRectMake(5, 0, 300, 37)]autorelease];
[lbl setBackgroundColor:[UIColor clearColor]];
[lbl setFont:[UIFont boldSystemFontOfSize:22]];
lbl.text = #"Some Text";
[lbl setTextAlignment:UITextAlignmentCenter];
[viewTemp addSubview:lbl];
return viewTemp;
}
Here i return one UIView in which i add UILable see above code so your whole view display with UILable properly and also set backGroundColor of UIView is clear so its display layout of UIPickerView.
I also display star like text in this UIPickerView.
See images Bellow..
Try this:
label.textAlignment = NSTextAlignmentCenter;
I have a Custom cell that shows a pickerView when you select a row.
Then you change the value and put it on detailTextLabel.
But this method get the value before it changes.
//Custom Cell
SimplePickerInputTableViewCell *cell = (SimplePickerInputTableViewCell *) [_tableView dequeueReusableCellWithIdentifier:cellIndentifier2];
if (!cell) {
cell = [[SimplePickerInputTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIndentifier2];
UIImageView *lineView2 = [[UIImageView alloc] initWithFrame:CGRectMake(-2, 45, 320, 10)];
lineView2.image = [UIImage imageNamed:#"linha_horizontal.png"];
[cell addSubview:lineView2];
_opcaoTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, 200, 20)];
_opcaoTitle.textAlignment = UITextAlignmentLeft;
_opcaoTitle.textColor = [UIColor blackColor];
_opcaoTitle.text = #"Pista - Feminino";
[cell addSubview:_opcaoTitle];
_opcaoValueF = [[UILabel alloc] initWithFrame:CGRectMake(180, 15, 100, 20)];
_opcaoValueF.textColor = [UIColor blackColor];
[cell addSubview:_opcaoValueF];
}
_opcaoValueF.text = [NSString stringWithFormat:#"R$ %#,00", _eventFemininoValue];
cell.selectionStyle = UITableViewCellSelectionStyleGray;
[cell setValue:#"0"];
return cell;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[_tableView deselectRowAtIndexPath:indexPath animated:YES];
NSString *s = [[[tableView cellForRowAtIndexPath:indexPath] detailTextLabel] text];
NSLog(#"String is: %#", s);
int i = [s intValue];
NSLog(#"This is the int value: %d", i);
}
SimplePicker.m
#import "SimplePickerInputTableViewCell.h"
#implementation SimplePickerInputTableViewCell
#synthesize delegate;
#synthesize value;
__strong NSArray *values = nil;
+ (void)initialize {
values = [NSArray arrayWithObjects:#"0", #"1", #"2", #"3", #"4", #"5", #"6", #"7", #"8", #"9", #"10", nil];
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
self.picker.delegate = self;
self.picker.dataSource = self;
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
// Initialization code
self.picker.delegate = self;
self.picker.dataSource = self;
}
return self;
}
- (void)setValue:(NSString *)v {
value = v;
self.detailTextLabel.text = value;
self.detailTextLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.backgroundColor = [UIColor clearColor];
if (![value isEqualToString:#"0"]) {
[self.picker selectRow:[values indexOfObject:value] inComponent:0 animated:YES];
}
_backgroundValue = [[UIImageView alloc] initWithFrame:CGRectMake(285, 3, 40, 40)];
_backgroundValue.image = [UIImage imageNamed:#"home_icon_popular.png"];
[self addSubview:_backgroundValue];
[self sendSubviewToBack:_backgroundValue];
}
#pragma mark -
#pragma mark UIPickerViewDataSource
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return [values count];
}
#pragma mark -
#pragma mark UIPickerViewDelegate
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return [values objectAtIndex:row];
}
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
return 44.0f;
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
return 300.0f; //pickerView.bounds.size.width - 20.0f;
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
self.value = [values objectAtIndex:row];
if (delegate && [delegate respondsToSelector:#selector(tableViewCell:didEndEditingWithValue:)]) {
[delegate tableViewCell:self didEndEditingWithValue:self.value];
}
}
The problem is that you are getting the value as soon as the new cell is created (the cell is probably not even drawn on the screen at this time). To solve this you should capture the value when the use dismisses the picker view.
From the additional code you provided
1) Set up a delegate for the table view cell:
cell.delegate = self;
You can do this right after you create it
2) Add an implementation of tableViewCell:didEndEditingWithValue:
- (void)tableViewCell:(UITableViewCell*)cell didEndEditingWithValue:(NSValue*)value
{
NSLog(#"Value is %#", value);
}
My UITableViewCell has UITextField inside, now I want to get UITextField data to be stored in database (using insert command) but how can I be able to access the UITableViewCell's UITextField data
#interface ELCTextfieldCell : UITableViewCell <UITextFieldDelegate> {
id delegate;
UILabel *leftLabel;
UITextField *rightTextField;
NSIndexPath *indexPath;
}
#implementation ELCTextfieldCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
leftLabel = [[UILabel alloc] initWithFrame:CGRectZero];
[leftLabel setBackgroundColor:[UIColor clearColor]];
[leftLabel setTextColor:[UIColor colorWithRed:.285 green:.376 blue:.541 alpha:1]];
[leftLabel setFont:[UIFont fontWithName:#"Helvetica" size:12]];
[leftLabel setTextAlignment:UITextAlignmentRight];
[leftLabel setText:#"Left Field"];
[self addSubview:leftLabel];
rightTextField = [[UITextField alloc] initWithFrame:CGRectZero];
rightTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[rightTextField setDelegate:self];
[rightTextField setPlaceholder:#"Right Field"];
[rightTextField setFont:[UIFont systemFontOfSize:17]];
// FOR MWF USE DONE
[rightTextField setReturnKeyType:UIReturnKeyDone];
[self addSubview:rightTextField];
}
return self;
}
//Layout our fields in case of a layoutchange (fix for iPad doing strange things with margins if width is > 400)
- (void)layoutSubviews {
[super layoutSubviews];
CGRect origFrame = self.contentView.frame;
if (leftLabel.text != nil) {
leftLabel.frame = CGRectMake(origFrame.origin.x, origFrame.origin.y, 90, origFrame.size.height-1);
rightTextField.frame = CGRectMake(origFrame.origin.x+105, origFrame.origin.y, origFrame.size.width-120, origFrame.size.height-1);
} else {
leftLabel.hidden = YES;
NSInteger imageWidth = 0;
if (self.imageView.image != nil) {
imageWidth = self.imageView.image.size.width + 5;
}
rightTextField.frame = CGRectMake(origFrame.origin.x+imageWidth+10, origFrame.origin.y, origFrame.size.width-imageWidth-20, origFrame.size.height-1);
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
if([delegate respondsToSelector:#selector(textFieldDidReturnWithIndexPath:)]) {
[delegate performSelector:#selector(textFieldDidReturnWithIndexPath:) withObject:indexPath];
}
return YES;
}
- (BOOL) textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString *textString = self.rightTextField.text;
if (range.length > 0) {
textString = [textString stringByReplacingCharactersInRange:range withString:#""];
}
else {
if(range.location == [textString length]) {
textString = [textString stringByAppendingString:string];
}
else {
textString = [textString stringByReplacingCharactersInRange:range withString:string];
}
}
if([delegate respondsToSelector:#selector(updateTextLabelAtIndexPath:string:)]) {
[delegate performSelector:#selector(updateTextLabelAtIndexPath:string:) withObject:indexPath withObject:textString];
}
return YES;
}
#interface RootViewController : UITableViewController <ELCTextFieldDelegate> {
NSArray *labels;
NSArray *placeholders;
}
#implementation RootViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.labels = [NSArray arrayWithObjects:#"First Name",
#"Last Name",
#"Email",
#"Phone Number",
nil];
self.placeholders = [NSArray arrayWithObjects:#"Enter First Name",
#"Enter Last Name",
#"Enter Email",
#"Phone Number (Optional)",
nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
ELCTextfieldCell *cell = (ELCTextfieldCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[ELCTextfieldCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
Try setting tag value to the textField and then retrieve the values.
Ex: rightTextField.tag = 1000; // don't use 0
Access the textField using,
UITextField *textField = (UITextField *)[self.view viewWithTag:1000];
I want to display two lots of text in two different footers in my table.
The text for section 3 uses titleForFooterInSection :
- (NSString *)tableView:(UITableView *)tv titleForFooterInSection:(NSInteger)section
{
if (section == 3)
return #"SOME TEXT FOR SECTION 3";
else
return #"";
}
and works great and is styled correctly.
I also want to add some more complicatedly formatted text (just left aligned really), so I create a label and add it to viewForFooterInSection, which works but is not padded (doesn't start at x = 20 & y = 20, starts hard up against the main windows edge) and is not styled like the other text.
- (UIView *)tableView:(UITableView *)tv viewForFooterInSection:(NSInteger)section
{
if (section == 1)
{
UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(20, 20, 100, 50)] autorelease];
label.text = #"SOME COMPLICATED TEXT FOR SECTION 1\r\n"
"\r\n"
"MORE TEXT HERE\r\n"
"AND HERE.\r\n"
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont systemFontOfSize:14];
label.shadowColor = [UIColor colorWithWhite:0.8 alpha:0.8];
label.textColor = [UIColor blueColor];
label.lineBreakMode = UILineBreakModeWordWrap;
label.textAlignment = UITextAlignmentLeft;
label.numberOfLines = 0;
[label sizeToFit];
return label;
}
else
return nil;
}
-(CGFloat)tableView:(UITableView *)tv heightForFooterInSection:(NSInteger)section
{
if (section == 1)
return 180.0f;
else if (section == 3)
return 50.0f;
else
return 0.0f;
}
To get the padding add the label into another view before returning that as the footer view;
- (UIView *)tableView:(UITableView *)tv viewForFooterInSection:(NSInteger)section
{
...
CGRect footerFrame = [tv rectForFooterInSection:1];
CGRect labelFrame = CGRectMake(20, 20, footerFrame.size.width - 40, footerFrame.size.height - 40);
UIView *footer = [[UIView alloc] initWithFrame:footerFrame];
UILabel *footerLabel = [[UILabel alloc] initWithFrame:labelFrame];
[footer addSubview:footerLabel];
[footerLabel release];
...
return footer;
}
NB: You might want to scope *footer better to avoid a memory leak or use autorelease.
I'm not sure what the system defaults are for the label it creates to hold the text you supply as the title for footer. I guess you'll need to experiment when creating the footer label as Google hasn't thrown anything useful up.
EDIT: Rather than put all the code in the viewForFooterInSection method I use a custom UIView;
#interface CustomHeaderView : UIView {
NSString *headerTitle;
}
#property (nonatomic, retain) NSString *headerTitle;
#end
#implementation CustomHeaderView
#synthesize headerTitle;
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
// create frame with padding
CGRect labelFrame = CGRectMake(8, 8, frame.size.width - 16, frame.size.height - 16);
UILabel *headerText = [[UILabel alloc] initWithFrame:labelFrame];
[headerText setNumberOfLines:0];
[headerText setFont:[UIFont boldSystemFontOfSize:14.0]];
[self addSubview:headerText];
[headerText release];
}
return self;
}
- (void)setHeaderTitle:(NSString *)title {
[title retain];
[headerTitle release];
UILabel *label = [[self subviews] objectAtIndex:0];
[label setText:title];
[label sizeToFit];
CGRect viewFrame = [self frame];
CGRect labelFrame = [label frame];
viewFrame.size.height = labelFrame.size.height + 16;
[self setFrame:viewFrame];
[self setNeedsLayout];
headerTitle = title;
}
- (void)dealloc {
[headerTitle release];
[super dealloc];
}
#end
This allows me to set my title text and have the header resize for the content. I lazy load this in my view controller;
#interface MyViewController
{
UIView *headerView;
}
- (UIView *) headerView;
#end
#implementation MyViewController
- (UIView *) headerView {
if(headerView)
return headerView;
float w = [[self view] bounds].size.width;
// height irrelevant as long as non zero custom view will resize
CGRect headerFrame = CGRectMake(0, 0, w, 32);
headerView = [[CustomHeaderView alloc] initWithFrame:headerFrame];
return headerView;
}
- (UIView *) tableView:(UITableView *)tv viewForHeaderInSection:(NSInteger)sec {
return [self headerView];
}
- (void) viewWillAppear:(BOOL)animated {
[(CustomHeaderView *)[self headerView] setHeaderTitle:#"My Custom Header"]];
}
#end
Make sure u return proper height in - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section; delegate method.
Does anyone know how to change the color of a row (or row background) in the UIPickerView control from the iPhone SDK? Similiar to the below title for row, however I would also like to change the color of the row:
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
Thank you.
Thanks Noah, that's exactly what I needed. I wanted to add the code here just in case anyone else needs (or wants to comment on :)
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
CGRect imageFrame = CGRectMake(0.0, 0.0, 15, 15);
UIImageView *label = [[[UIImageView alloc] initWithFrame:imageFrame] **autorelease**];
if (row == 0)
{
label.backgroundColor = [UIColor redColor];
}
if (row == 1)
{
label.backgroundColor = [UIColor blueColor];
}
if (row == 2)
{
label.backgroundColor = [UIColor blackColor];
}
return label;
}
You can return an arbitrary view in the delegate's -pickerView:viewForRow:forComponent:reusingView: method, documented here.
I implemented the following based on Sean's answer:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
CGRect rowFrame = CGRectMake(00.0f, 0.0f, [pickerView viewForRow:row forComponent:component].frame.size.width, [pickerView viewForRow:row forComponent:component].frame.size.height);
UILabel *label = [[UILabel alloc] initWithFrame:rowFrame];
label.font = [UIFont boldSystemFontOfSize:18.0f];
// This is an array I pass to the picker in prepareForSegue:sender:
label.text = [self.values objectAtIndex:row];
label.textAlignment = UITextAlignmentCenter;
// This is an array I pass to the picker in prepareForSegue:sender:
if ([self.backgroundColors count]) {
label.backgroundColor = [self.backgroundColors objectAtIndex:row];
// self.lightColors is an array I instantiate in viewDidLoad: self.lightColors = #[ [UIColor yellowColor], [UIColor greenColor], [UIColor whiteColor] ];
label.textColor = [self.lightColors containsObject:label.backgroundColor] ? [UIColor blackColor] : [UIColor whiteColor];
} else {
label.textColor = [UIColor blackColor];
}
return label;
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
UILabel *labelSelected = (UILabel*)[pickerView viewForRow:row forComponent:component];
[labelSelected setTextColor:[UIColor redColor]];
}
And
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel *label = (id)view;
if (!label){
label=[[UILabel alloc]init];
label.textAlignment = NSTextAlignmentCenter;
pickerView.backgroundColor=[UIColor whiteColor];
label.text=[self pickerView:pickerView titleForRow:row forComponent:component];
label.textColor=[UIColor grayColor];
}
return label;
}
Do this:
label.backgroundColor = [UIColor yourcolorColor];