UIAlertController size, Font, swift 4


This is a way to modify UIAlertAction, but only for title and color button.
if anyone can modify the font size from the comment below.

It look like this :



@IBAction func button(_ sender: Any) {
        
        let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
        alert.view.tintColor = #colorLiteral(red: 0.6642242074, green: 0.6642400622, blue: 0.6642315388, alpha: 1)
        
        //to change font of title and message.
        let messageFont = [kCTFontAttributeName: UIFont(name: "Avenir-Roman", size: 14.0)!]
        let messageAttrString = NSMutableAttributedString(string: "Message Here", attributes: messageFont as [NSAttributedStringKey : Any])
        
        alert.setValue(messageAttrString, forKey: "attributedMessage")

        alert.addAction(UIAlertAction(title: "Lorem Ipsum ", style: .default, handler: { _ in
          self.navigationController?.pushViewController(DetailPaketViewController(), animated: false)
        }))
        
        alert.addAction(UIAlertAction(title: "Lorem Ipsum", style: .default, handler: { _ in
            print("test link")
        }))
        
        alert.addAction(UIAlertAction(title: "Lorem Ipsum", style: .default, handler: { _ in
            print("test link")
        }))
        
        alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
        present(alert, animated: true)
    }



Buy me a coffeeBuy me a coffee

1 comment: