开发者

Iphone Pickerview Ellipsis at start instead of end

开发者 https://www.devze.com 2023-01-24 12:03 出处:网络
Just as the title states, is it at all possible to place the ellipsis (...) at the beggining of a UIPickerView \"row\" instead of the end?

Just as the title states, is it at all possible to place the ellipsis (...) at the beggining of a UIPickerView "row" instead of the end?

I tried both returning a NSString and a UIView for:

pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component

I even tried wrapping the view with a scroller to try to find alte开发者_开发知识库rnate solutions to what I wanted, but it seems that ellipsis at the beggining is still what would suit me best.

The end of the text is a unique identifier, where as the beggining may be repeated among various objects, that why the end of the text is more importante.

This isnt what im doing, but think of for example a list with name and the social security number for the person, the name may be repeated, the ssn will not.

I know I could just place the number at the beggining, but this app is runing various platforms in this way, and the customer really wants the numbers to stay at the end to keep consistency.

Is this even possible? If so, how could I do it?

Thanx, Stefano.

Answer code added:

- (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.text = [self.arrayWithData objectAtIndex:row];
    retval.lineBreakMode = UILineBreakModeHeadTruncation;
    retval.backgroundColor = [UIColor clearColor];

    return retval;
}


You can do this by implementing the –pickerView:viewForRow:forComponent:reusingView: method on your UIPickerViewDelegate instead of the –pickerView:titleForRow:forComponent: method. The latter just returns a string to the UIPickerView, at which point it's up to the picker view to determine how to display it. At that point, you don't have control over where to show ellipses.

Instead, implement –pickerView:viewForRow:forComponent:reusingView:, returning a UILabel with its lineBreakMode set to UILineBreakModeHeadTruncation. That will ensure the ellipses is put at the beginning of the string.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号