Question

The title is fairly specific about what I want to do. I have a custom view and have drawn some elements inside that view. How do I change the autosizing properties programmtically? I have looked around and couldn't find anything that would help me in my case.

Objective C:

- (void)drawRect:(NSRect)HTMLContent { 
    NSGraphicsContext* gc = [NSGraphicsContext currentContext];
    [gc saveGraphicsState];
    int height = [[NSScreen mainScreen] frame].size.height;
    int screenwidth = [[NSScreen mainScreen] frame].size.width;
    int emailInnerContentWidth = screenwidth - 510;

    // Horizontal Line
    [[NSColor colorWithCalibratedRed:.8 green:.82 blue:.83 alpha:1] setFill];
    NSBezierPath* drawingPath = [NSBezierPath bezierPathWithRect:NSMakeRect(337, 570, emailInnerContentWidth, 2)];
    [drawingPath fill];

    // Social Icon
    NSRect outrect = NSMakeRect(355, 585, 58, 58);
    [[NSColor lightGrayColor] setStroke];
    [[NSColor colorWithPatternImage:[NSImage imageNamed:@"NoSocialIcon.png"]] setFill];
    NSBezierPath* outcirclePath = [NSBezierPath bezierPath];
    [outcirclePath appendBezierPathWithOvalInRect: outrect];
    [[NSColor lightGrayColor] setStroke];[[NSImage imageNamed:@"NoSocialIcon.png"] drawInRect:outrect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1];
    [outcirclePath stroke];

    // Restore graphics state
    [gc restoreGraphicsState];
}

I want to set these 2 shapes to not be affected by the bottom of the window changing. I want it to change when the top of the window changes height. I have looked on the Apple docs and nothing seemed to work. Thanks in advance

Was it helpful?

Solution

So, for each of the two shapes:

[shape setAutoresizingMask:NSViewNotSizable | NSViewMaxXMargin | NSViewMinYMargin];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top