SoFunction
Updated on 2025-04-11

How to add more features to web hosting pages

Preface

catchPrevious article, In the Settings Center, we usually jump to a certain web page hosting page, and we usually add some features to improve its experience.

1. Add the effect of chrysanthemum loading

2. Add the function to jump to Safari

3. Add a copy link function

4. Add the function of sharing web pages

First, taking the WebViewController as an example, we want to create a UIWebView; then we create three function buttons on the left and a button that closes the page on the right, and binds them separately; the display and hiding of the load button are directly implemented through the code. The code for the head state is as follows:

class WebViewController: UIViewController,UIWebViewDelegate{
 let spinner = UIActivityIndicatorView()
 @IBOutlet weak var WebView: UIWebView!

 @IBAction func CloseAction(_ sender: Any) {
  (animated: true, completion: nil)
 }

 @IBAction func SafariAction(_ sender: Any) {
  ()
 }

 @IBAction func CopyAction(_ sender: Any) {
  ()
 }

 @IBAction func MoreAction(_ sender: Any) {
  ()
 }

1. Add the effect of chrysanthemum loading

The loading button needs to appear in the center immediately when the page is loaded, and start rotating the guide page to be hidden after successfully loading.

First add the loading chrysanthemum immediately appears when the page is loading. The code is as follows:

override func viewDidLoad() {
  ()
  //Chrysanthemum button   = .gray
   = 
   = true
  (spinner)
  ()

  ()
  // Do any additional setup after loading the view.
}

After that, webViewDidFinishLoad detects the loading status of the page. When the loading is completed, it immediately hides and stops the rotation of the chrysanthemum. The code is as follows:

func webViewDidFinishLoad(_ webView: UIWebView) {
  print("web load finish")
  ()
 }

2. Add the function of jumping to Safari

The function toSafari that opens the browser is bound during initialization, and the operation of opening the browser is very simple:

@objc func toSafari(){
  print("to safari")
  if let url = NSURL(string:) {
   (url as URL, options: [:], completionHandler: nil)
  }
}

3. Add a copy link function

To Copy the web page information method to Copy, we can copy the title and link at the same time, the code is as follows:

@objc func toCopy(){
  print("to copy")
  // Just these two sentences are realized  let paste = 
  let str = +":"+
  print(str)
   = str
  let alertController = UIAlertController(title: NSLocalizedString("Copy Success!",comment: "Copy Success!"),message: nil,preferredStyle: .alert)
  //Show the prompt box  (alertController, animated: true, completion: nil)
  //It disappears automatically after two seconds  (deadline: () + 2) {
   ?.dismiss(animated: false, completion: nil)
  }
}

4. Add the function of sharing web pages

The method to share web pages toMore adopts a method similar to sharing applications. This is the content here that we changed to the information of the web page, such as the title, link, and header image of the web page. The code is as follows:

@objc func toMore(){
  print("to more")
  let shareVC:UIActivityViewController = UIActivityViewController(activityItems: [,,], applicationActivities: nil)
  (shareVC, animated: true, completion: {
   print("more success")
  })
 }

Are three functions very simple with one feature? Of course you need to add another close button.

Summarize

The above is the entire content of this article. I hope that the content of this article has a certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.