How to Change the UISlider to Vertical?

前端 未结 3 1380
既然无缘
既然无缘 2021-02-07 01:04

I am customizing an UISlider for my app. I want the slider to be in vertical orientation, but the default UISlider is in horizontal orientation. I coul

3条回答
  •  [愿得一人]
    2021-02-07 01:48

    In case you are using auto layouts:

    In your viewDidLoad, try:

    UIView *superView = self.sizeSlider.superview;
    [self.sizeSlider removeFromSuperview];
    [self.sizeSlider removeConstraints:self.view.constraints];
    self.sizeSlider.translatesAutoresizingMaskIntoConstraints = YES;
    self.sizeSlider.transform = CGAffineTransformMakeRotation(M_PI_2);
    [superView addSubview:self.sizeSlider];
    

    It does not work with constraints, so the trick is to remove the constraints for your uislider. You might have to resize it manually by setting its frame property.

提交回复
热议问题