I have UIPickerView with two columns and in one column I want to display image and label next to it. It works. Display and image and label, just label is under image how to put image on the left, and label on the right side? I tried to changle label align to right but it doesnt work.
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row
forComponent:(NSInteger)component reusingView:(UIView *)view
{
if(component == kStateComponent)
{
UIImage *img = [UIImage imageNamed:@"rts1.png"];
UIImageView *temp = [[UIImageView alloc] initWithImage:img];
temp.frame = CGRectMake(0, 0, 29, 29);
UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
channelLabel.text = @"sdfsdfdsf";
channelLabel.textAlignment = UITextAlignmentLeft;
channelLabel.backgroundColor = [UIColor clearColor];
UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 110, 60)];
[tmpView insertSubview:temp atIndex:0];
[tmpView insertSubview:channelLabel atIndex:1];
return tmpView;
}
...
}
Set appropriate frame for your channelLabel. To position it to the left of the imageView set correct frame origin x coordinate value (1st parameter in CGRectMake function), e.g:
UILabel *channelLabel = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 60, 60)];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With