分類  >  Web前端 >

【iPhone代碼片段之六】代碼(不使用xib)創建UIWebView

tags:    時間:2013-12-10 08:04:06
【iPhone代碼片段之六】代碼(不使用xib)創建UIWebView .
代碼如下:

-(void)initWebView{     UIView *view = [[ UIView alloc] initWithFrame:[ UIScreen                                                    mainScreen].applicationFrame] ;     self.view = view;          CGRect webFrame = CGRectMake(0.0,0.0,350.0,450.0);     //webFrame.origin.y+=25;     UIWebView *webView = [[UIWebView alloc] initWithFrame:webFrame];     [webView setBackgroundColor:[UIColor whiteColor]];//設置北京為白色     webView.scalesPageToFit = YES;//適應屏幕大小          NSString * strURL = @"http://blog.csdn.net/m_changgong";     NSURL * url = [NSURL URLWithString:strURL];     NSURLRequest * request = [NSURLRequest requestWithURL:url];     [webView loadRequest:request];          [self.view addSubview:webView];     [webView release]; }




在-(void)loadView方法中調用initWebView:[self initWebView];即可,效果如圖:

[img]

[/img]

推薦閱讀文章

Bookmark the permalink ,來源:互聯網