iphone uipickerview with images - iphone

it's possible add as item in the uipickerview some images/icons instead of text?
thanks

yes it is absolutely possible. u need to handle pickerView delegate method
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view
here you simply return custom view(could be anything UIImage UILabel)
and set userInteractionEnable property to no for customize view..

Related

Disable delegate methods depending on iOS version

I'm using some UIPickerView delegate methods only for the brand-new-Ive-modified iOS under NDA, e.g.
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
I don't want to implement them for iOS6, to preserve default iOS behavior, so a condition inside the method won't work. How to do it?
In your delegate, override respondsToSelector: and return NO in case of old OS:
- (BOOL)respondsToSelector:(SEL)selector
{
if (selector == #selector(pickerView:viewForRow:forComponent:reusingView:))
return MyFunctionThatChecksIosVersionIsMinimum7();
return [super respondsToSelector:selector];
}
So you're implementing the delegate method normally. When the picker view is asking your delegate if it understands the message you're simply lying to it.

Set font as per width

Hello friends I am displaying text in UIPickerview row. But when the label size is too big then Picker row displays ... at the end of the label.
I want to display whole title in row of Picker instead of this. Can i set the font size automatically as per the title width in pickerview.
You need to implement following method:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
tView = [[UILabel alloc] init];
// Setup label properties - frame, font, colors etc
...
}
// Fill the label text here
...
return tView;
}
Make your controller a UIPickerViewDelegate and UIPickerViewDataSource, then you can use this routine to make any custom change you want for your picker row:
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
//make your own view here, it can be a UILabel if you want, or other kind of view.
//You can give it any size font you need.
}

UIPickerView Font

Does anyone know if it is possible to change the font and/or color for individual UIPickerView Items?
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
tView = [[UILabel alloc] init];
// Setup label properties - frame, font, colors etc
...
}
// Fill the label text here
...
return tView;
}
Yes, it is possible. To do that you need to implement pickerView:viewForRow:forComponent:reusingView: method in picker's delegate - create UILabel instance there and setup it with whatever attributes you want.
For this, I would simply go with attributed strings.
Implement this method is your delegate:
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView
attributedTitleForRow:(NSInteger)row
forComponent:(NSInteger)component

How to call the picker view content in a table view?

how to call the picker view content in table view..is there any method to call the picker view content?pls help me...
I think you would have used this delegate to put your content into the picker.
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return yourPickerContentArray;
}
I think that yourPickerContentArray will have the content of the picker. why dont you use that array where you want.

UIPicker With View + View Tapped != Selected Row

Hey! I have a UIPicker, and I am using the function:
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view {
But, when you tap one of the views returned by this function, the tapped view does not become highlighed, and selected if the touch is released. How can I fix that?
Make use of this property,
pickerView.showsSelectionIndicator = YES;
at initialization.