Simple About Box in Swift

Here is a really simple example of how to create an about box from a UIAlertController in iOS using Swift. The box displays the application icon, the current version and some text about the application:


        let alertMessage = UIAlertController(title: "Camping Directory", message: "", preferredStyle: .alert)
        
        // Application Icon
        let image = UIImage(named: "AppIcon40x40")
        
        let imageView = UIImageView(frame: CGRect(x: 115, y: 48, width: 40, height: 40))
        imageView.image = image
        imageView.layer.cornerRadius = 8.0
        imageView.clipsToBounds = true
        
        alertMessage.view.addSubview(imageView)
        
        // Application Version
        let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
        
        // Description
        var message = "nnnVersion " + version! + "nn"
        message += "This program is..."
        
        alertMessage.message = message
        
        let action = UIAlertAction(title: "OK", style: .default, handler: nil)
        alertMessage .addAction(action)
        
        self.present(alertMessage, animated: true, completion: nil)
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *