Hi all, I’m trying to get the accessory view of an NSAlert to layout similarity to the the text fields of the messageText and informativeText. That is:
* Fill the the available horizontal space of the alert, respecting margins * Including accounting for the different margins of the normal and wide appearance * Overflow any content of the accessory view by increasing its height * Never contributing to increasing the width of the alert itself But attempts at doing this with auto layout constraints have failed me, as merely setting translatesAutoresizingMaskIntoConstraints = NO for my view to set up constraints seems to break the margins that NSAlert applies to the accessory view, and I don’t know how to restore them. Looking at the disassembly of NSAlert (_buildLayoutConstraintsForWideAppearance e.g.) it seems to use constraint based layout, with the accessory view is wrapped inside another view (accessoryContainer), but if I print out the constraints of the views in play all I see are instances of NSAutoresizingMaskLayoutConstraint. And inspecting the views in the hierarchy, they all respond YES to translatesAutoresizingMaskIntoConstraints. Perhaps this is a red herring, but shouldn’t I be seeing non-autoresizing constants here? How would one expand the accessory view to fill its superview (accessoryContainer), in a way that keeps the accessoryContainer’s position and margins in both normal and wide apperance? Here’s a reproducer of some of the things I’m seeing: #import <Cocoa/Cocoa.h> int main() { bool triggerWideApperance = true; NSString *loremIpsum = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; loremIpsum = [@"" stringByPaddingToLength:(triggerWideApperance ? 5 : 1) * loremIpsum.length withString:loremIpsum startingAtIndex:0]; NSAlert *alert = [NSAlert new]; alert.messageText = loremIpsum; alert.informativeText = loremIpsum; // Attempt 1: Disables the wide alert apperance, making the alert super wide alert.accessoryView = [NSTextField wrappingLabelWithString:loremIpsum]; // Attempt 2: Retains the wide alert apperance, but loses the left margin of the accessory view, alert.accessoryView = [NSStackView stackViewWithViews:@[ [NSTextField wrappingLabelWithString:loremIpsum] ]]; [alert layout]; [alert runModal]; } Thanks for any tips or insights on this! Cheers, Tor Arne _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com