UISlider with ProgressView combined

后端 未结 9 1385
无人共我
无人共我 2020-11-29 16:07

Is there an apple-house-made way to get a UISlider with a ProgressView. This is used by many streaming applications e.g. native quicktimeplayer or youtube. (Just to be sure:

9条回答
  •  清酒与你
    2020-11-29 16:45

    You can do some trick like this, it's more easy and understanding. Just insert the code bellow in your UISlider subclass.

    - (void)layoutSubviews
    {
        [super layoutSubviews];
    
        if (_availableDurationImageView == nil) {
            // step 1 
            // get max length that our "availableDurationImageView" will show
            UIView *maxTrackView = [self.subviews objectAtIndex:self.subviews.count - 3];
            UIImageView *maxTrackImageView = [maxTrackView.subviews objectAtIndex:0];
            _maxLength = maxTrackImageView.width;
    
            // step 2
            // get the right frame where our "availableDurationImageView" will place in       superView
            UIView *minTrackView = [self.subviews objectAtIndex:self.subviews.count - 2];
            _availableDurationImageView = [[UIImageView alloc] initWithImage:[[UIImage     imageNamed:@"MediaSlider.bundle/4_jindu_huancun.png"]     resizableImageWithCapInsets:UIEdgeInsetsMake(0, 2, 0, 2)]];
            _availableDurationImageView.opaque = NO;
            _availableDurationImageView.frame = minTrackView.frame;
    
            [self insertSubview:_availableDurationImageView belowSubview:minTrackView];
        }
    }
    
    
    - (void)setAvailableValue:(NSTimeInterval)availableValue
    {
        if (availableValue >=0 && availableValue <= 1) {
            // use "maxLength" and percentage to set our "availableDurationImageView" 's length
            _availableDurationImageView.width = _maxLength * availableValue;
        }
    }
    

提交回复
热议问题