Pages

Subscribe:

Tuesday, February 8, 2011

Using image & text together or custom view in a UIPickerView

-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {

UIButton *customButton = [UIButton buttonWithType:UIButtonTypeCustom];
customButton.frame=CGRectMake(5,5, 50, 50);
UIImage *anImage=[UIImage imageNamed:yourImage];
[customButton setImage:anImage forState:UIControlStateNormal];

UILabel *lblTemp = [[UILabel alloc] initWithFrame:CGRectMake(60, 5, 400, 50)];
lblTemp.text = [NSString stringWithFormat:yourText];

UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 460, 60)];
[tempView addSubview:lblTemp];
[tempView addSubview:customButton];
[view addSubview:tempView];

[lblTemp release];
[tempView release];

return tempView;
}

1 comment:

Erfan said...

This is a delegate method for UIPickerView

Post a Comment