Search code examples
iosswiftuislidercgrectmake

Changing UISlider x and y position


I have viewController with slider inside and I need to change the position of slider programmatically. I am using following code:

mySliderOutlet.frame = CGRectMake(100, 250, mySliderOutlet.frame.size.width, mySliderOutlet.frame.size.height)

Problem is this doesn't do anything. Outlet is connected correctly, I am using it elsewhere in the code to read values from slider. I will be glad for any suggestions. Thanks.


Solution

  • Please make sure, following this are done before setting the frames on your slider

    1. Autolayout is turned off and sizing classes are disabled in the storyboard.Here is how to do it
    2. Turn off the 'auto resize subview' for the view inside the viewcontroller from storybaord.Uncheck the autoresize subview option
    3. Make sure this frame update your'e doing must be done in Main thread or main queue.