How to calculate the correct size for scaling WebView?

I have a webview in my window. When the user clicks the Zoom button (green button in the upper left corner of the window), I want to resize the window so that the WebView is large enough to show the web page as recommended in the Mac HCI guidelines.

Question: How do I calculate the size of a WebView to increase?

Thank.

+3
source share
1 answer

Sorry, then you must cancel it :)

- (IBAction)resizeToView:(id)sender
{
    // webview content sub/document-view
    NSView *docView =[[[webView mainFrame] frameView] documentView]; 
    NSRect docRect = [docView frame];

    // height and width
    int height = docRect.size.height;
    int width = docRect.size.width;

    NSRect frame = [window frame];
    int delta = height - frame.size.height;

    // y/height
    frame.origin.y -= delta;
    frame.size.height += delta;

    // x/width
    frame.size.width = width; 

    [window setFrame:frame display:YES]; 
}
+1
source

Source: https://habr.com/ru/post/1795969/


All Articles