iOS cannot change frame of UIButton

前端 未结 5 564
醉酒成梦
醉酒成梦 2021-01-04 06:23

I am currently stuck with a very weird problem. I am using iOS 6 and Xcode 4.5. I have a storyboard with a UIViewController and a UIButton in it. I

相关标签:
5条回答
  • 2021-01-04 07:10

    I had the same weird problem using XCode 4.5 and iOS 6 as deployment target. I am not using story board though. I managed to solve it by disabling the option "Use Autolayout" in the Interface Builder. (In the file inspector->Interface builder document.

    Hope this helps

    0 讨论(0)
  • 2021-01-04 07:14

    You can change frame of your UIButton by changing layer's frame of UIButton

     [self.button.layer setFrame:] 
    

    import QuartzCore framework in your class header before using this. This will work with auto layout also.

    0 讨论(0)
  • 2021-01-04 07:15

    Remove the view from the superview and after setting frame add this view again as a subview. Hope this will work fine...

    0 讨论(0)
  • 2021-01-04 07:16

    //Remove the view from the superview

    UIView *view = yourButton.superview;
    [yourButton removeFromSuperview];
    

    //change frame of UIButton

    CGRect bounds = view.bounds;
    yourButton.center = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
    

    //add this view again as a subview

    [view addSubview:yourButton];
    
    0 讨论(0)
  • 2021-01-04 07:24

    You can use this

    [_button setTranslatesAutoresizingMaskIntoConstraints:YES];
    

    after this you can set frame of your button.

    It may give some warnings in log about constraints, as this property override constraints you gave in autolayout.

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