我创建了 UIImageView
的自定义子类,并且在一种方法中,我想在加载图像时向中心添加一个事件指示器。我正在使用以下代码,但事件监视器位于 UIImageView
之外。我该怎么做才能使它恰好在 UIImageView
的范围内居中?
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
indicator.autoresizingMask =
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleBottomMargin |
UIViewAutoresizingFlexibleLeftMargin;
indicator.center = self.center;
[self addSubview:indicator];
[indicator startAnimating];
最佳答案
center
属性是 View 在其 superview 坐标空间中的坐标。因此,您需要在 imageView 的坐标空间中设置指示器的坐标。正确的方法是:
indicator.center = CGPointMake(CGRectGetMidX(self.bounds), CGRectGetMidY(self.bounds));
关于objective-c - 在 UIImageView 中居中 UIActivityIndicatorView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10781291/