How do I change the color of the text in a UIPickerView under iOS 7?

There is a function in the delegate method that is more elegant: Objective-C: – (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component { NSString *title = @”sample title”; NSAttributedString *attString = [[NSAttributedString alloc] initWithString:title attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}]; return attString; } If you want to change the selection bar colors as well, I found that I had to add 2 … Read more

Responding to touchesBegan in UIPickerView instead of UIView

I’ve been searching for a solution to this problem for over a week. I’m answering you even if you’re question is over a year old hoping this helps others. Sorry if my language is not very technical, but I’m pretty new to Objective-C and iPhone development. Subclassing UIpickerView is the right way to do it. … Read more

Xcode 8 / Swift 3 : Simple UIPicker code not working

UIPickerViewDataSource method numberOfComponentsInPickerView is changed in Swift 3 like this that is the reason you are getting this error. func numberOfComponents(in pickerView: UIPickerView) -> Int { return 1 } func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { return muteForPickerData.count } func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { … Read more

How do you shrink a UIPickerView on the iPhone?

Actually, you can slightly shrink the whole UIPickerView by applying an affine transform to an enclosing view. For example: CGSize pickerSize = [pickerView sizeThatFits:CGSizeZero]; pickerTransformView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, pickerSize.width, pickerSize.height)]; pickerTransformView.transform = CGAffineTransformMakeScale(0.75f, 0.75f); [pickerTransformView addSubview:pickerView]; [self.view addSubview:pickerTransformView]; [pickerTransformView release]; will scale a picker to 75% of its original size by placing it … Read more

Change UIPickerView background

You could also mask the component. With a bit fiddeling you can get the size of the component and cut it out with following code: CALayer* mask = [[CALayer alloc] init]; [mask setBackgroundColor: [UIColor blackColor].CGColor]; [mask setFrame: CGRectMake(10.0f, 10.0f, 260.0f, 196.0f)]; [mask setCornerRadius: 5.0f]; [picker.layer setMask: mask]; [mask release]; Don’t forget #import <QuartzCore/QuartzCore.h>

Fixed labels in the selection bar of a UIPickerView

Create your picker, create a label with a shadow, and push it to a picker’s subview below the selectionIndicator view. It would look something like this UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(135, 93, 80, 30)] autorelease]; label.text = @”Label”; label.font = [UIFont boldSystemFontOfSize:20]; label.backgroundColor = [UIColor clearColor]; label.shadowColor = [UIColor whiteColor]; label.shadowOffset = CGSizeMake (0,1); … Read more

UIDatePicker select Month and Year

Here is a solution to get the same effect. For using this snippet of code you should replace UIPickerView to CDatePickerViewEx in nib file in “Custom class” of “Indentity inspector”. .h file #import <UIKit/UIKit.h> @interface CDatePickerViewEx : UIPickerView <UIPickerViewDelegate, UIPickerViewDataSource> @property (nonatomic, strong, readonly) NSDate *date; -(void)selectToday; @end .m file #import “CDatePickerViewEx.h” // Identifiers of … Read more

How to change UIPickerView height

It seems obvious that Apple doesn’t particularly invite mucking with the default height of the UIPickerView, but I have found that you can achieve a change in the height of the view by taking complete control and passing a desired frame size at creation time, e.g: smallerPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 120.0)]; You … Read more