How do you implement an MPVolumeView?

2019-02-12 19:13发布

I want the user to be able to change the system volume with a slider, and I realized the only way to do this is with an MPVolumeView.

But I can't find any example code for it, and every method I try to implement won't show up.

So what is the easiest and correct, working way of implementing a MPVolumeView?

2条回答
何必那么认真
2楼-- · 2019-02-12 19:35

Use this it will automatically get it

mpVolumeViewParentView.backgroundColor = [UIColor clearColor];
MPVolumeView *myVolumeView = [[MPVolumeView alloc] initWithFrame: mpVolumeViewParentView.bounds];
[mpVolumeViewParentView addSubview: myVolumeView];
[myVolumeView release];
查看更多
唯我独甜
3楼-- · 2019-02-12 19:41

Place it as a regular slider, then use the inspector to set the class to MPVolumeView. It'll still be shown as a regular slider in IB, but at runtime, it will be an instance of MPVolumeView and will have the necessary styles and behavior.

查看更多
登录 后发表回答