我在网上搜索也没有解决这个问题。我有一个事件指示器 View ,其中包含一个我想自定义的图层。更具体地说,我想增加它的大小。问题是事件指示器不再以其背景为中心。
这应该是相当简单的事情,但我不知道该怎么做。管理层似乎比添加其他 subview 更简洁。
这是我通过下面的代码得到的结果。
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activityView setColor:[UIColor whiteColor]];
activityView.layer.frame = CGRectMake(self.view.bounds.size.width/2-30, self.view.bounds.size.height/2-30, 60, 60);
activityView.layer.cornerRadius = 5;
[activityView.layer setBackgroundColor:[[UIColor colorWithRed:2/255.0 green:79/255.0 blue:105/255.0 alpha:0.9] CGColor]];
activityView.center = self.view.center;
//activityView.center = also tried to center on layer, layer.contentsRect,... without any success;
[activityView startAnimating];
[self.view addSubview:activityView];
如果有人能帮助我...
最佳答案
您可以使用它来居中事件:
activityView.subviews[0].center = CGPointMake(CGRectGetMidX(activityView.bounds), CGRectGetMidY(activityView.bounds));
但我认为这是不好的方式。尝试在不改变其框架的情况下制作 View 并将 Activity 添加到该 View 。
关于ios - 在其图层上居中事件指示器 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42781902/