Vertical UISlider in iOS with autolayout

后端 未结 10 1883
难免孤独
难免孤独 2021-02-07 07:22

As per my iPad app requirement, i\'ve to show the UISlider vertically.
I\'m using iOS7 compiler and deployment target is iOS6.
In the story board I added horizontal UISl

相关标签:
10条回答
  • 2021-02-07 07:45

    Uncheck Auto-Layout on your ViewController, there is no other option under the SDK 7.0 to make it work vertically :(

    0 讨论(0)
  • 2021-02-07 07:50

    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.

    0 讨论(0)
  • 2021-02-07 07:50

    You can't use storyboard to build up a UISlider. Build up UISlider by coding.

    slider = [[UISlider alloc] initWithFrame:CGRectMake(640, 150, 600, 400)];
    [slider.layer setAnchorPoint:CGPointMake(0.0f, 0.0f)];
    slider.transform = CGAffineTransformMakeRotation(M_PI/2);
    [self.view addSubview:slider];
    
    0 讨论(0)
  • 2021-02-07 07:50

    For me a two-step process worked best (incorporating some of the previous solutions)

    Autolayout step) I added a vertical view in IB and used autolayout to link it to neighboring views. Then I added a slider in the view and simply hooked it up to the center of the view. Then hooked up the width of the slider to the height of the view. Finally control-dragged the slider outlet to my ViewController code (as slider)

    Code step) Then simply added the to my viewWillAppear (swift-code):
    let trans = CGAffineTransformMakeRotation(CGFloat(M_PI_2)); slider.transform = trans;

    0 讨论(0)
提交回复
热议问题