gpt4 book ai didi

ios - 很难将 UIActivityIndi​​cator 放入 UIButton

转载 作者:行者123 更新时间:2023-11-29 02:15:29 25 4
gpt4 key购买 nike

我在将 UIActivityIndi​​cator 放入 UIButton 时遇到了一些问题。这是它的样子:

enter image description here

这是我总是得到的:

enter image description here

使用此代码:

  self.activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];

CGFloat halfButtonHeight = self.updateEventButton.bounds.size.height / 2;
CGFloat buttonWidth = self.updateEventButton.bounds.size.width;
self.activityView.center = CGPointMake(buttonWidth - halfButtonHeight , halfButtonHeight);

[self.subSubView addSubview:self.activityView];
[self.activityView startAnimating];

我希望指示器位于右下角的底部。只需看看指示器现在的位置,然后考虑是否将它向下拖动到按钮,然后再向右拖动一点。

我的 View 是这样设置的:

enter image description here

最佳答案

您正在计算与按钮相关的坐标系中的指示器位置,但随后将其作为 subview 添加到不同的 View 中,因此坐标不正确。要解决此问题,您可以直接向按钮添加指示器 View :

[self.updateEventButton addSubview:self.activityView];

或者将按钮坐标系中的点转换为self.subSubView的坐标系,然后再将其设置为activityView:

CGPoint centerInButton = CGPointMake(buttonWidth - halfButtonHeight, halfButtonHeight);
self.activityView.center = [self.updateEventButton convertPoint:centerInButton
toView:self.subSubView];

关于ios - 很难将 UIActivityIndi​​cator 放入 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28798399/

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