【发布时间】:2018-09-13 20:23:58
【问题描述】:
我的应用正在使用 WKWebView 加载我的网站。我需要一个带有自定义深灰色背景视图的 UiActivityIndicator,因为当 UIActivityIndicator 与我的网站内容混合时可能难以发现。之前,我跟随https://coderwall.com/p/su1t1a/ios-customized-activity-indicator-with-swift 以编程方式创建指标。但是,本教程使用默认白色,而我的是大白色和自定义橙色。我只需要一个在backgroundView 内带有指示器的backgroundView。它以某种方式工作,直到我注意到指示器不在那个中心并且它向左上角跑了一点。请看这张图片,
这在我的 iPhone 5 等上非常明显。所以,我使用了另一种使用自动布局的方法。背景视图仍然无法正常工作。这是我的自动布局设置
这是我的编程部分。
loadingView.frame = CGRect(x: 0, y: 0, width: 60, height: 60)
loadingView.center = self.view.center
loadingView.backgroundColor = UIColor(red:211/255,green:211/255,blue:211/255, alpha: 1)
loadingView.clipsToBounds = true
loadingView.layer.cornerRadius = 10
loadingIndicator.frame = CGRect(x: 0, y: 0, width: 30, height: 30)
loadingIndicator.isOpaque = false
loadingIndicator.center = CGPoint(x: loadingView.frame.size.width / 2.0, y: loadingView.frame.size.height / 2.0)
loadingIndicator.backgroundColor = UIColor.gray
loadingIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyle.whiteLarge
loadingIndicator.color = UIColor(red:232/255,green:126/255,blue:4/255,alpha:1.0)
loadingIndicator.hidesWhenStopped = true
loadingView.addSubview(loadingIndicator)
self.view.addSubview(loadingView)
我更喜欢使用自动布局。
【问题讨论】:
-
我认为您需要将这一行中的 2.0 更改为 2
loadingIndicator.center = CGPoint(x: loadingView.frame.size.width / 2.0, y: loadingView.frame.size.height / 2.0)
标签: ios uiactivityindicatorview