Created
July 18, 2011 15:11
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <MediaPlayer/MediaPlayer.h> | |
@interface MPVolumeView (ReferenceView) | |
+ (MPVolumeView *)swapWithReferenceView:(UIView *)referenceView; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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