4

I am using MPVolumeView for my App. I have Customized the MPVolumeView but there's a problem as the thumb image of slider not Properly set.

rptwsthi
  • 10,094
  • 10
  • 68
  • 109
Hitendra
  • 1,610
  • 1
  • 15
  • 22
  • Welcome Hitendra, a well formatted question attract more responders, so try formatting your question with suggested formatting patterns that are, http://stackoverflow.com/editing-help and also you like to see asking keynotes here: http://stackoverflow.com/editing-help to get maximum response on your question, without any downvote. :) – rptwsthi Feb 18 '13 at 11:57
  • When asking a question, please properly format it, and include all of the relevant details. In this question, it was not clear that you were asking about the layout of the image that you set, instead of the "thumb image of slider not Properly set." which can mean many different things depending on the context. – ekinnear Jun 20 '13 at 18:56
  • Also, if you find an answer that properly answers your question, please mark it as the answer by clicking the icon to the left of the answer. – ekinnear Jun 20 '13 at 18:56

2 Answers2

0

In MPVolumeView,

Its always using volume value with your device hardware volume value.

if your hardware has minimum volume as 0.2 then your MPVolumeView set slider on 0.2. it uses 0.0 to 1.0 value for volume.

For more detail you download sample code here,

Sample Code

You can also customise this volume view

Help Link

Let me know if you need anymore.

UPDATE :

One more helpful link here, MPVolumeView

Community
  • 1
  • 1
Solid Soft
  • 1,872
  • 2
  • 25
  • 55
  • I have download the sample code that you given the link. but in that sample code the thumb image is not set. and in my application i have set the thumb image it is not displaying properly.it shows thumb a few pixels down. – Hitendra Feb 18 '13 at 12:35
  • yes i know that i am using in device. i have link http://tibr.me/2012/07/14/customizing-mpvolumeview-appearance/ but i am not getting that. – Hitendra Feb 18 '13 at 13:01
  • for (UIButton *button in volumeView.subviews) { if ([button isKindOfClass:[UIButton class]]) { [button setImage:[UIImage imageNamed:@"custom-route-button.png"] forState:UIControlStateNormal]; [button sizeToFit]; } } ------ This loop is helpful to get every subview and set images on that.. – Solid Soft Feb 18 '13 at 13:03
  • http://tibr.me/2012/07/14/customizing-mpvolumeview-appearance/ perfectly working with me.. – Solid Soft Feb 18 '13 at 13:12
  • I can confirm that the last (link)[tibr.me/2012/07/14/customizing-mpvolumeview-appearance] posted by @Jagdish is entirely covering the issue - I did use the information described in that posting for a project of mine. – Till Feb 18 '13 at 13:15
  • @Hitendra but all code is shown within that article, what else would you need? – Till Feb 18 '13 at 13:16
  • @Hitendra You will get code help whatever you need, But don't expect from some one who write whole code for you. At least you need to do some of at your end too. What's exactly issue you are facing for this task ? – Solid Soft Feb 18 '13 at 13:58
0

Edit:

So it turns out that when using MPVolumeView, iOS doesn't actually vertically align the image that you set the same way it does with other images. The solution is to create a slightly offset image (you can always use alpha if you need to convince it that the image is larger) and use that one just for the MPVolumeView. This is kind of a pain, but works very well. Usually you want between 2-4 pixels of offset for your new image.


To set the volume thumb image, you should use:

setVolumeThumbImage:forState:

For example, if you have an image that is called myThumbImage.png and an MPVolumeView called myVolumeView, you would use:

[myVolumeView setVolumeThumbImage:
    [UIImage imageNamed:@"myThumbImage"] forState:UIControlStateNormal];

This will find any image named myThumbImage.png that exists in your project, and it will use it for the slider thumb. You should take care that this image is the size you want, 25x25 is usually a little big, but not a bad starting point.

Apple's UISlider will dim and change the button's appearance when you tap on it. To accomplish this, create another image that looks how you want it (this may be the same image, just darker, or a completely different one altogether), and set it to be the image displayed for the thumb when it is highlighted (which is what happens when you tap on it).

You would accomplish this using:

[myVolumeView setVolumeThumbImage:
    [UIImage imageNamed:@"VolumeThumbHighlighted"] forState:UIControlStateHighlighted];

Which will find the image named VolumeThumbHighlighted.png and use it for that purpose.


Note that you can also set the left and right track images, with stretchable images, with slightly different methods than the typical UISlider ones. You would use this code:

[myVolumeView setMinimumVolumeSliderImage:[[UIImage imageNamed:@"LeftTrackImage"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 4, 0, 0)]forState:UIControlStateNormal];
[myVolumeView setMaximumVolumeSliderImage:[[UIImage imageNamed:@"RightTrackImage"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 4)]forState:UIControlStateNormal];

This sets the image to have edge insets of 4, you can make that whatever value you would like.

I'm not going to fully explain this part, since it is not directly a part of your question.

ekinnear
  • 437
  • 2
  • 10