0

I can't seem to increase the font size of my NSAlert - or even the size of the entire box.

else if array[arraycount].containsString("Error: error.") {
   let myPopup: NSAlert = NSAlert()
   myPopup.alertStyle = NSAlertStyle.WarningAlertStyle
   myPopup.addButtonWithTitle("I've Called!")
   myPopup.informativeText = "Sorry, we weren't able to that. Please Call Support 1(800)234-4567 ext: 12345"
   myPopup.runModal()
   let app = NSRunningApplication.currentApplication()                           
   app.activateWithOptions(.ActivateIgnoringOtherApps)
 }

This is my current code which works fine, but I will be running my OS X application on an iMac and the text looks really small. I was wanting to increase the point size programmatically, but I can't find anything about it in Swift. Any help would be appreciated!

  • 2
    The documentation of NSAlert is in English, did you try to read it? Did you see `messageText`? – Willeke Jul 29 '16 at 15:40
  • I actually wanted to set my font size, not just use a predefined one. I wasn't able to find anything to do that, even though I can read English. :-) – cheesydoritosandkale Aug 22 '16 at 20:23

2 Answers2

1

Don't set informativeText, that's really small.

Instead, set messageText. That's much bigger, and bold.

Even better, set both, so more important information is big and bold and less important information is small.

myPopup.messageText = "Sorry, we weren't able to that."
myPopup.informativeText = "Please Call Support 1(800)234-4567 ext: 12345"
tbodt
  • 16,609
  • 6
  • 58
  • 83
1

There is also the option to use accessoryView in the alert.

let accessory = NSTextView(frame: CGRect(x: 0, y: 0, width: 200, height: 20))
let attributes : [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: NSFont.systemFont(ofSize: 13)]
let accessoryText = "Some more readable text"
let accessoryAttributedText = NSAttributedString(string: accessoryText, attributes: attributes)
accessory.textStorage!.setAttributedString(accessoryAttributedText)
accessory.isEditable = false
accessory.drawsBackground = false
alert.accessoryView = accessory
claude31
  • 874
  • 6
  • 8
  • 1
    The OP accepted an answer long ago, but you can also set properties of the default text fields via their subview in the alert window’s contentView. – red_menace Apr 26 '21 at 02:20