NSAlert resizing window
I have multiple NSAlert dialogs with different text. I want to adjust the width of the alert box for the text so that the text doesn't wrap. So I am using this code to calculate the line width:
NSSize size = [myString sizeWithAttributes:@{NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSize]]}];
Then I try to customize the alert box:
NSAlert *alert = [NSAlert alertWithMessageText:...
...
NSPanel *panel = alert.window;
NSRect frame = panel.frame;
float x = ((NSTextField*)[[((NSPanel*)(alert.window)).contentView subviews] objectAtIndex:5]).frame.origin.x; //the x-position of the NSTextField
frame.size.width = size.width + x;
[alert.window setFrame:frame display:YES];
This code works, but only the first time I call the method using this code. If I take a different line and call the method again, the window will not change (although the calculated width will differ).
Any ideas how I can resize the NSAlert window?
+3
source to share