码迷,mamicode.com
首页 > 移动开发 > 详细

ios navigationcontroller 滑动返回与webview加载html图片自适应屏幕宽度

时间:2014-12-18 20:44:50      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:navigationcontroller   webview   html   

1 、ios navigationcontroller 滑动返回

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

解决的办法有两个:

       ①   

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

只能用

self.navigationItem.backBarButtonItem =   

   [ [UIBarButtonItem alloc]initWithTitle: style: target: action:]

选择范围较小,

     ②

    UIButton*button = [UIButton buttonWithType:UIButtonTypeCustom];

    [button setFrame:CGRectMake(0, 0, 40, 40)];

    [button setTitle:@"返回" forState:UIControlStateHighlighted];

    [button setTitle:@"返回" forState:UIControlStateNormal];

    [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];

    

    

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

  

    self.navigationItem.leftBarButtonItem = bar;

    

但是要在push之后加上

if ([self.navigationController respondsToSelector:@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_content appendString:@"<html>"];

    [data_content appendString:@"<head>"];

    [content appendString:@"<meta charset=\"utf-8\">"];

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

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

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

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

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

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

    [content appendString:@"<title>webview</title>"];

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

ios navigationcontroller 滑动返回与webview加载html图片自适应屏幕宽度

标签:navigationcontroller   webview   html   

原文地址:http://blog.csdn.net/lv_ruanruan/article/details/42008873

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!