IOS开发(1)使用WebView显示网页。
利用ios webview控件来显示html页面进行app开发。不过速度和效果肯定比原声的查好多。前提条件mac电脑,没有使用虚拟机安装os 系统。虚拟机(vmware)安装mac网上一大堆教程。安装XCode。创建项目创建 Single View Application 项目,项目使用的是OC语言开发,所以语言选择Objective C项目结构:* info.p
·
利用ios webview控件来显示html页面进行app开发。不过速度和效果肯定比原声的查好多。
前提条件
- mac电脑,没有使用虚拟机安装os 系统。虚拟机(vmware)安装mac网上一大堆教程。
- 安装XCode。
创建项目
创建 Single View Application 项目,项目使用的是OC语言开发,所以语言选择Objective C
项目结构:
* info.plist:*
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UIStatusBarHidden</key>
<true/>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
ViewController.m:
//
// ViewController.m
// Restaurant
//
// Created by 汝玉林 on 2018/1/26.
// Copyright © 2018年 witsystem. All rights reserved.
//
#import "ViewController.h"
//设备的宽高
#define SCREENWIDTH [UIScreen mainScreen].bounds.size.width
#define SCREENHEIGHT [UIScreen mainScreen].bounds.size.height
@interface ViewController ()
@property (nonatomic, strong) UIWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0,SCREENWIDTH, SCREENHEIGHT)];
NSString *url = @"http://www.baidu.com";
NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[self.view addSubview: self.webView];
[self.webView loadRequest:request];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
运行预览:
修改完毕直接运行即可,就能看到响应的html界面。
更多推荐
已为社区贡献2条内容
所有评论(0)