iOS cannot change frame of UIButton

前端 未结 5 661
醉酒成梦
醉酒成梦 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: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];
    

提交回复
热议问题