gpt4 book ai didi

ios - 如何使用 Swift 创建自定义类加载 View

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

我正在通过自定义类加载 View 实现加载概念。我需要通过使用简单的 self.show() 来使用这个自定义类和 self.dismiss功能。在这里,我通过使用 UIActivityController 实现了这个概念。在 UIAlertView 内但我需要使用自定义类来做到这一点。

下面是我使用 UIActivityController 实现的代码在 UIAlertView

func loadinHubShow() {
let alert = UIAlertController(title: nil, message: "Please wait...", preferredStyle: .alert)
let loadingIndicator = UIActivityIndicatorView(frame: CGRect(x: 10, y: 5, width: 50, height: 50))
loadingIndicator.hidesWhenStopped = true
loadingIndicator.style = UIActivityIndicatorView.Style.gray
loadingIndicator.startAnimating();
alert.view.addSubview(loadingIndicator)
present(alert, animated: true, completion: nil)
}

func loadinHubDismiss() {
dismiss(animated: false, completion: nil)
}

如何将其更改为自定义类 loading view .我不想使用 UIActivityControllerUIAlertView 内, 或者需要创建相同的外观和感觉 UI design通过 UIView .

最佳答案

import Foundation
import UIKit

public class Indicator {

public static let sharedInstance = Indicator()
var blurImg = UIImageView()
var indicator = UIActivityIndicatorView()

private init()
{
blurImg.frame = UIScreen.main.bounds
blurImg.backgroundColor = UIColor.black
blurImg.isUserInteractionEnabled = true
blurImg.alpha = 0.5
indicator.style = .whiteLarge
indicator.center = blurImg.center
indicator.startAnimating()
indicator.color = .red
}

func showIndicator(){
DispatchQueue.main.async( execute: {

UIApplication.shared.keyWindow?.addSubview(self.blurImg)
UIApplication.shared.keyWindow?.addSubview(self.indicator)
})
}
func hideIndicator(){

DispatchQueue.main.async( execute:
{
self.blurImg.removeFromSuperview()
self.indicator.removeFromSuperview()
})
}
}

关于ios - 如何使用 Swift 创建自定义类加载 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57782976/

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