UIWebView on iOS

I am creating an application that requires half of the page to be a web view and the other half to be filled with other things. The problem is that when I compose the view in the UI builder, it has the correct width and height, but when I really load it, it fills the whole screen.

Here is the code:

- (void)loadView  
{  
    // Create a custom view hierarchy.  
    CGRect appFrame = [[UIScreen mainScreen] applicationFrame];  
    UIView *view = [[UIView alloc] initWithFrame:appFrame];  
    self.view = view;  
    [view release];  

    CGRect webFrame = [[UIScreen mainScreen] applicationFrame];  
    webView = [[UIWebView alloc] initWithFrame:webFrame];  
    webView.backgroundColor = [UIColor whiteColor];  
    [self.view addSubview:webView]; 

    NSString *html = @"<html><head><title>Should be half</title></head><body>I wish the answer were just 42</body></html>";  
    [webView loadHTMLString:html baseURL:nil];  
}  
+3
source share
1 answer

You do not need most of this code. Generally speaking, you either create your view hierarchy programmatically in loadView, or use the Interface Builder to do this graphically. You did the same - you created your view in Interface Builder, and then threw it all away and did it programmatically.

loadView . , Builder. loadView nib .

, webView IBOutlet Interface Builder. , nib. , UIWebView, Interface Builder ivar.

viewDidLoad, -. nib , , , , HTML -. - :

- (void)viewDidLoad
{  
    NSString *html = @"<html><head><title>Should be half</title></head><body>I wish the answer were just 42</body></html>";  
    [webView loadHTMLString:html baseURL:nil];
}
+4

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


All Articles