Uislider Handle Changes Width on Different Size Ipads

UISlider changing width depending on device

Instead of hard coding the values, you could get the container views width and set the sliders width as a percentage of it.

CGRect superViewFrame = slider.superView.frame;
CGRect sliderFrame = slider.frame;
sliderFrame.size.width = <your choice for eg, superViewFrame.size.width * 0.3f>
sliderFrame.origin.x = <your choice for eg, superViewFrame.size.width * .2f>
slider.frame = sliderFrame;

Fit a Vertical UISlider into an Existing Container View?

There is no problem with this code to add and rotate the slider. The problem is that the the code must be put into the "layoutSubviews" method of the slider's parent view; instead I had it in the "layoutSubviews" of the parent view of the parent view of the slider. When my original code executed the slider's parent view had not yet been laid out and did not yet have the correct dimensions.

During "layoutSubviews" of a view, the subviews have not yet been laid out and so their bounds are not yet valid. I needed to wait until later in the layout process to get the bounds of the parent view and transform the slider to fit.

In the end, I put the code to add the slider and transform the slider in the "viewDidAppear" of the top level view controller. This was the same code as in the original question - just in a different place.

Scaling a font on a multilined UIButton depending on a device size

You can use size classes to specify the font on your button/label in IB. Just press the little + sign to the left of the font property:

Just press the little + sign to the left of the font property



Related Topics



Leave a reply



Submit