zl程序教程

您现在的位置是:首页 >  其它

当前栏目

UIWebView without a .xib Objective-C[转]

Objective Without UIWebView
2023-09-14 08:59:42 时间

Add a UIWebView programmatically without using a .xib file. This goes in the views controller. Original fromhttp://www.gibsontang.com/?p=176 (Big thanks man!)

- (void) initUIWebView {
NSLog(@”DetailViewController- initUIWebView {“);

UIWebView *aWebView;

// init and create the UIWebView
aWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
aWebView.autoresizesSubviews = YES;
aWebView.autoresizingMask=(UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth);

//set the web view delegates for the web view to be itself
[aWebView setDelegate:self];

//Set the URL to go to for your UIWebView
NSString *urlAddress = @”http://www.google.com”;

//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];

//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];

//load the URL into the web view.
[aWebView loadRequest:requestObj];

//add the web view to the content view
[self.view addSubview:aWebView];

[aWebView release], aWebView = nil;

}

- (void)viewDidLoad {

[self initUIWebView]; // this calls the UIWebView Function
[super viewDidLoad];

}

欢迎加群互相学习,共同进步。QQ群:iOS: 58099570 | Android: 330987132 | Go:217696290 | Python:336880185 | 做人要厚道,转载请注明出处!
【iOS】 含tableView的ViewController基类的实现 上篇博客写了ViewController的基类的实现,这篇博客主要写在BaseViewController的基础上实现一个含tableView控件的基类的实现,主要给包含tableView的页面来继承。
iOS开发中,创建View常见的两种方式一个是纯代码,一个是借助于XIB;创建ViewController常见的也有两种方式一个是纯代码,一个是借助于StoryBoard。