How to change ios volume in swift with help UISlider - ios

I wrote the following code, but it doesn't change iOS System Volume, it only changes the sound from within the app.
audioPlayer is subclass of AVAudioPlayer
#IBAction func sliderVol(sender: UISlider) {
audioPlayer.volume = sender.value
}
The UISlider has the sent event of value changed
How can I change iOS system volume with help UISlider?

The MPVolumeView class is designed to let you do exactly this. It's in MediaPlayer framework. So, add that to your app to make things build correctly.
You create it and make it visible the way you instantiate any other subclass of UIView, which you probably know by now.
You can provide your own frame and use this to change the system volume.
var wrapperView = UIView(frame: CGRectMake(30, 200, 260, 20))
self.view.backgroundColor = UIColor.clearColor()
self.view.addSubview(wrapperView)
// 3
var volumeView = MPVolumeView(frame: wrapperView.bounds)
wrapperView.addSubview(volumeView)
For more help you can look here Controlling system volume using swift

Related

MPVolumeView route button not showing consistently in IOS 11 update

I created IOS app for live streaming with use of AVPlayer. I add the airplay routes button with help of MPVolumeView.
After update of IOS 11, airplay routes button not coming up properly on screen.
Sometime it show on screen sometimes not showing on screen
Anybody help me with it, is it IOS 11 issues or their some change need to MPVolumeView done in my code.
I am using AVPlayerViewController, in which i added MPVolumeView as subview.
self.airButton.frame = CGRect(x:0,y:0,width:45,height:45)
self.airButton.backgroundColor = UIColor.green
let volumeView = MPVolumeView(frame : self.airButton.frame )
volumeView.showsVolumeSlider = false
volumeView.showsRouteButton = true
volumeView.backgroundColor = UIColor.red
self.airButton.addSubview(volumeView)
self.airButton.translatesAutoresizingMaskIntoConstraints = false
self.controlView.addSubview(airButton)
Thanks

Title of UIButton is not visible when UIVibrancyEffect is applied

I'm having trouble applying UIVibrancyEffect to my UIButtons in iOS today widget. I want them to like default "Edit" button in notification centre's Today section:
As you can see in the screenshot, default button is vibrant and looks much better.
I tried replacing widget's View with UIVisualEffectView like that:
UIVisualEffectView effectView = new UIVisualEffectView(UIVibrancyEffect.CreateForNotificationCenter ());
effectView.Frame = this.View.Bounds;
effectView.AutoresizingMask = this.View.AutoresizingMask;
UIView oldView = this.View;
this.View = effectView;
effectView.ContentView.AddSubview(oldView);
this.View.TintColor = UIColor.Clear;
And it appears to be working, but titles of my buttons become vibrant as well (I want them to remain black):
Is there a way to prevent button titles from becoming vibrant when UIVibrancyEffect is applied?
I should also add that I'm using Xamarin.iOS.
I seem to have a solution to my own problem. I ended up creating UIVisualEffectView with blank UIView inside and adding it behind UIButton.
This code snippet shows how to style one button:
// Create effect view
var effectView = new UIVisualEffectView(UIVibrancyEffect.CreateForNotificationCenter ());
// This color looks best for me. You can play around with it to make it look better
effectView.BackgroundColor = UIColor.FromRGBA(55, 55, 55, 100);
// Position effectView
effectView.Frame = myButton.Frame;
// Add effectView and send it to back, behind actual button
this.View.AddSubview(effectView);
this.View.SendSubviewToBack (effectView);
// Create UIView and add it to effectView's ContentView
var view = new UIView ();
view.BackgroundColor = UIColor.White;
effectView.ContentView.AddSubview(view);
view.Frame = new CGRect(0, 0, effectView.Frame.Width, effectView.Frame.Height);
// Make sure your effect view has rounded corners
effectView.Layer.MasksToBounds = true;
effectView.Layer.CornerRadius = 4.0f;
And this is how it looks:

Simple Overlay View on UIImagePickerControler.Camera

I am initiating a camera capture via UIImagePickerController (sourceType = .Camera)
I have created a simple ViewController overlayVC and designed it in IB
I wish to overlay overlayVC on top of the camera now. How do I accomplish this in swift?
I understand I need to use UIImagePickerController.cameraOverlayView property but this property wont take overlayVC directly. What step am I missing?
I figured it out my self:
let overlay = self.storyboard?.instantiateViewControllerWithIdentifier("OverlayVC")
image.cameraOverlayView = overlay?.view

Custom like button IOS SDK

it is possible to customize the facebook like button SDK? I need my turn Button image or set the background of the button as image
var likeControl:FBSDKLikeControl = FBSDKLikeControl()
likeControl.objectID = fbPage
likeControl.likeControlStyle = FBSDKLikeControlStyle.BoxCount
likeControl.backgroundColor = UIColor(patternImage: UIImage(named: "fblike")!)
likeControl.frame = CGRectMake(16,20, 290, 40)
self.viewBotoes.addSubview(likeControl)
You can't assign your own background image to the FBSDKLikeControl, which is inherited from the UIControl
FBSDKLikeControl is exposing only a few properties such as foregroundColor, FBSDKLikeControlAuxiliaryPosition, FBSDKLikeControlHorizontalAlignment, likeControlStyle, preferredMaxLayoutWidth and soundEnabled

MPVolumeView with XCode 4 (Storyboards)

How do you make a slider that adjusts the volume level of the device with storyboarding? I haven't found any information on this relevant to XCode 4. Is MPVolumeView still the way to go? If so, how do I implement it?
Thanks.
You can still use an MPVolumeView in Xcode 4.x and iOS5. Simply import the MediaPlayer framework (link to it in your project settings, too) and use something like this:
MPVolumeView *volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(0,0,120,15)];
[someView addSubview:volumeView];
This will give you the slider that will change system volume when dragged.
If you want to use a slider, you can add one to your view and link it to an action in the corresponding view controller. The action looks like this:
- (IBAction)volumeSliderChanged:(id)sender
{
UISlider *slider = (UISlider *)sender;
float newVolume = slider.value;
// Set new volume
}

Resources