当前位置: 代码迷 >> Web前端 >> 【iPhone代码片断之六】代码(不使用xib)创建UIWebView
  详细解决方案

【iPhone代码片断之六】代码(不使用xib)创建UIWebView

热度:221   发布时间:2012-08-29 08:40:14.0
【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];即可,效果如图:



  相关解决方案