Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom MPVolumeView Thumb Image not vertically centered since iOS 5.1

I'm building an application that needs an MPVolumeView to control the volume. It worked perfectly before iOS 5.1 but since the 5.1 update the thumb image is no longer vertically centered. I tried a few things like changing imagine dimensions, resizing my views (and slider) but nothing seems to work, the thumb is just not vertically centered anymore. The only way i get a centered thumb is if i use the default iOS one.

I tried adding a UISlider to another view with the exact min, max and thumb image and that one is centered fine.

Here is the code for the MPVolumeView:

MPVolumeView *volumeView;
volumeView = [[[MPVolumeView alloc] initWithFrame:volumeViewHolder.bounds] autorelease];
[volumeViewHolder addSubview:volumeView];

UIView  *volumeViewSlider;
for (UIView *view in [volumeView subviews])
{
    if ([[[view class] description] isEqualToString:@"MPVolumeSlider"])
    {
        volumeViewSlider = view;
    }
}

[(UISlider *)volumeViewSlider setThumbImage:sliderHandleIcon forState:UIControlStateNormal];
    [(UISlider *)volumeViewSlider setMinimumTrackImage:leftTrackImage forState:UIControlStateNormal];
    [(UISlider *)volumeViewSlider setMaximumTrackImage:rightTrackImage forState:UIControlStateNormal];

volumeViewHolder is just a UIView thats 153x33. I put the thumb in green in the screenshot. enter image description here

like image 488
Hulk_SMASH Avatar asked Jun 27 '12 16:06

Hulk_SMASH


1 Answers

Maybe a better solution:

User a bigger image with a transparent border on the bottom. Should be around 10px for Retina Displays.

like image 54
Nilz11 Avatar answered Sep 20 '22 11:09

Nilz11