UIWebView代理
@property (nullable, nonatomic, assign) id <UIWebViewDelegate> delegate;
UIWebView代理方方法
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType;
- (void)webViewDidStartLoad:(UIWebView *)webView;
- (void)webViewDidFinishLoad:(UIWebView *)webView;
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error;
web请求数据及加载数据
- (void)loadRequest:(NSURLRequest *)request;
- (void)loadHTMLString:(NSString *)string baseURL:(nullable NSURL *)baseURL;
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL;
loadRequest方法:这是加
载网页最常用的一种方式,通过一个网页URL来进行加载,这个URL可以是远程的也可以是本地的
loadHTMLString方法:这个方法需要将html文件读取为字符串
web执行JS代码(OC调用JS的代码)
- (nullable NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)script;
缩放内容
@property (nonatomic) BOOL scalesPageToFit;
网页内容转化为可点击链接
使用UIDataDetectorTypes将电话,网址,邮件变为链接
@property (nonatomic) UIDataDetectorTypes dataDetectorTypes NS_AVAILABLE_IOS(3_0);
typedef NS_OPTIONS(NSUInteger, UIDataDetectorTypes) {
UIDataDetectorTypePhoneNumber = 1 << 0, // Phone number detection
UIDataDetectorTypeLink = 1 << 1, // URL detection
UIDataDetectorTypeAddress NS_ENUM_AVAILABLE_IOS(4_0) = 1 << 2, // Street address detection
UIDataDetectorTypeCalendarEvent NS_ENUM_AVAILABLE_IOS(4_0) = 1 << 3, // Event detection
UIDataDetectorTypeShipmentTrackingNumber NS_ENUM_AVAILABLE_IOS(10_0) = 1 << 4, // Shipment tracking number detection
UIDataDetectorTypeFlightNumber NS_ENUM_AVAILABLE_IOS(10_0) = 1 << 5, // Flight number detection
UIDataDetectorTypeLookupSuggestion NS_ENUM_AVAILABLE_IOS(10_0) = 1 << 6, // Information users may want to look up
UIDataDetectorTypeNone = 0, // Disable detection
UIDataDetectorTypeAll = NSUIntegerMax // Enable all types, including types that may be added later
} __TVOS_PROHIBITED;
实例:
UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 20, 280, 200)];
textView.dataDetectorTypes = UIDataDetectorTypeAll;
textView.font = [UIFont systemFontOfSize:20];
textView.editable = NO;
textView.text = @"My phone number is +8602980000000.\r\n"
"My personal web site www.xxxxxx.com.\r\n"
"My E-mail address is XXXXX@gmail.com.\r\n"
"I was born in 1900-01-01.";
[self.view addSubview:textView];!
网页播放器
@property (nonatomic) BOOL allowsInlineMediaPlayback ; // iPhone Safari defaults to NO. iPad Safari defaults to YES
@property (nonatomic) BOOL mediaPlaybackRequiresUserAction ; // iPhone and iPad Safari both default to YES
@property (nonatomic) BOOL mediaPlaybackAllowsAirPlay ; // iPhone and iPad Safari both default to YES
allowsInlineMediaPlayback:默认使NO。这个值决定了用内嵌HTML5播放视频还是用本地的全屏控制。为了内嵌视频播放,不仅仅需要在这个页面上设置这个属性,还必须的是在HTML中的video元素必须包含webkit-playsinline属性。
mediaPlaybackRequiresUserAction:在iPhone和iPad上默认使YES。这个值决定了HTML5视频可以自动播放还是需要用户去启动播放
分页模式
@property (nonatomic) UIWebPaginationMode paginationMode ;
typedef NS_ENUM(NSInteger, UIWebPaginationMode) {
UIWebPaginationModeUnpaginated,
UIWebPaginationModeLeftToRight, 从左往右分页显示
UIWebPaginationModeTopToBottom, 从上往下分页显示
UIWebPaginationModeBottomToTop, 从下往上分页显示,倒着显示
UIWebPaginationModeRightToLeft 从右往左分页显示
} __TVOS_PROHIBITED;
分页 长度 页面之间差值 分页个数
分页的长度
@property (nonatomic) CGFloat pageLength ;
多个页面之间的差值
@property (nonatomic) CGFloat gapBetweenPages ;
分页的个数
@property (nonatomic, readonly) NSUInteger pageCount ;
是否网页内容下载完毕才开始渲染web视图,默认为NO
@property (nonatomic) BOOL suppressesIncrementalRendering NS_AVAILABLE_IOS(6_0); // iPhone and iPad Safari both default to NO
设置用户交互模式,默认YES
@property (nonatomic) BOOL keyboardDisplayRequiresUserAction NS_AVAILABLE_IOS(6_0); // default is YES