IOS侧滑和webview

1 、ios navigationcontroller 滑动返回

滑动返回是navigationcontroller默认返回按钮自带的功能,如果返回按钮自定义该功能失效,

解决的办法有两个:

self.navigationItem.backBarButtonItem =   [[UIBarButtonItemalloc]initWithCustomView:button];//这个方法用不了

只能用

self.navigationItem.backBarButtonItem =   

[ [UIBarButtonItem alloc]initWithTitle: styletarget: action:]

选择范围较小,

UIButton*button = [UIButtonbuttonWithType:UIButtonTypeCustom];

[buttonsetFrame:CGRectMake(0,0,40,40)];

[buttonsetTitle:@"返回"forState:UIControlStateHighlighted];

[buttonsetTitle:@"返回"forState:UIControlStateNormal];

[buttonaddTarget:selfaction:@selector(back)forControlEvents:UIControlEventTouchUpInside];

 

 

UIBarButtonItem*bar = [[UIBarButtonItemalloc]initWithCustomView:button];

self.navigationItem.leftBarButtonItem= bar;

 

但是要在push之后加上

if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {

self.navigationController.interactivePopGestureRecognizer.delegate=nil;

}

2、webview加载html图片自适应屏幕宽度

在用webview加载html的时候如果碰到html中有图片的时候,如果不对html做一下处理的话,会发现,加载出来的图片有些是对

屏幕不会自己适配的,这个时候处理的时候有两种方法,

①对webview做下处理,

self.mWebView.scalesPageToFit=YES;

这个方法不完善,图片是会适配屏幕,但是字体会变小,

②写一个webview的拓展类

里面对html文本用js或者css做一下处理,添加一个一个head

[data_contentappendString:@"<html>"];

[data_contentappendString:@"<head>"];

[contentappendString:@"<meta charset=/"utf-8/">"];

[contentappendString:@"<meta id=/"viewport/" name=/"viewport/" content=/"width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=false/" />"];

[contentappendString:@"<meta name=/"apple-mobile-web-app-capable/" content=/"yes/" />"];

[contentappendString:@"<meta name=/"apple-mobile-web-app-status-bar-style/" content=/"black/" />"];

[contentappendString:@"<meta name=/"black/" name=/"apple-mobile-web-app-status-bar-style/" />"];

[contentappendString:@"<style>img{width:100%;}</style>"];

[contentappendString:@"<style>table{width:100%;}</style>"];

[contentappendString:@"<title>webview</title>"];

这个处理的比较完美,也可以加在html的尾部,但是没有放在头部灵活,

posted @ 2015-01-26 18:32  luseike  阅读(943)  评论(0编辑  收藏  举报