Using storyboards -
Step 1: Drag and Drop the UIWebView into the View
Step 2: Then go to the .h file (for this particular view) and create an IBOutlet UIWebView. For instance -
// MainViewController.h @interface MainViewController : UIViewController @property (nonatomic, strong) IBOutlet UIWebView *myWebView; @end
Step 3. Go to the storyboard and create a connection to the output of myWebView (this can be found in the Xcode inspector area) in the UIWebView by dragging and dropping the control.
Step 4: Now that we have the connection, we just need to go to .m (for this particular view) and add the following code -
//MainViewController.m @implementation MainViewController - (void)viewDidLoad { [super viewDidLoad]; NSString *urlNameInString = @"https://www.google.com"; NSURL *url = [NSURL URLWithString:urlNameInString]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; [self.myWebView loadRequest:urlRequest]; } @end
source share