gpt4 book ai didi

ios - 按钮方向问题

转载 作者:行者123 更新时间:2023-11-28 22:39:22 25 4
gpt4 key购买 nike

我以编程方式创建一个按钮,并将其框架指向我在 Storyboard上创建的另一个按钮,当方向发生变化时,它不会像预期的那样停留在中间。

我还创建了一个 UIImageview 但当方向改变时它会停留在中间

@property (nonatomic, weak) IBOutlet UIImageView *logoImage;
@property (nonatomic, weak) IBOutlet UIButton *loginButton;
@property (strong, nonatomic) UIButton* popUpButton;

UIImage *logOutButtonImage=[UIImage imageNamed:@"Button - Logout.png"];
_popUpButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_popUpButton setBackgroundImage:logOutButtonImage forState:UIControlStateNormal];
_popUpButton.frame=_loginButton.frame;
[_popUpButton addTarget:self action:@selector(didPressLink:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:_popUpButton];

Storyboard上的图像和按钮,它们在中间

enter image description here

图像的属性

enter image description here

按钮属性

enter image description here

结果:

在 View didload 上正常工作,无论方向是什么:

enter image description here

方向改变时不会停留在中间

enter image description here

为什么按钮不在中间,我该如何实现?

最佳答案

设置自动调整掩码

_popUpButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

关于ios - 按钮方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14988394/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com