Fixed labels in the selection bar of a UIPickerView

前端 未结 12 1243
一生所求
一生所求 2020-11-27 12:17

In the clocks application, the timer screen shows a picker (probably a UIPicker in UIDatePickerModeCountDownTimer mode) with some text in the selec

12条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 12:52

    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);
    [picker insertSubview:label aboveSubview:[picker.subviews objectAtIndex:5]]; 
    //When you have multiple components (sections)...
    //you will need to find which subview you need to actually get under
    //so experiment with that 'objectAtIndex:5'
    //
    //you can do something like the following to find the view to get on top of
    // define @class UIPickerTable;
    // NSMutableArray *tables = [[NSMutableArray alloc] init];
    // for (id i in picker.subviews) if([i isKindOfClass:[UIPickerTable class]]) [tables addObject:i];
    // etc...
    
    

    -- Pay it forward

提交回复
热议问题