Skip to content

Instantly share code, notes, and snippets.

@axiixc
Created July 18, 2011 15:11
Show Gist options
  • Save axiixc/1089804 to your computer and use it in GitHub Desktop.
Save axiixc/1089804 to your computer and use it in GitHub Desktop.
Really handy way to work with MPVolumeView since it doesn't have an IB component. Just create a UIView, and call this from -viewDidLoad, it will make sure to center and swap in a volume view.
#import <MediaPlayer/MediaPlayer.h>
@interface MPVolumeView (ReferenceView)
+ (MPVolumeView *)swapWithReferenceView:(UIView *)referenceView;
@end
#import "MPVolumeView+ReferenceView.h"
@implementation MPVolumeView (ReferenceView)
+ (MPVolumeView *)swapWithReferenceView:(UIView *)referenceView
{
MPVolumeView * volumeView = [[MPVolumeView alloc] initWithFrame:referenceView.frame];
[volumeView sizeToFit];
[volumeView setCenter:referenceView.center];
[volumeView setAutoresizingMask:referenceView.autoresizingMask];
[referenceView.superview addSubview:volumeView];
[referenceView removeFromSuperview];
return [volumeView autorelease];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment