phonegap ios7 StatusBar 状态栏

很早就在弄这个导航栏。但是都是失败告终。今天终于解决这个问题!

define("cordova/plugin/statusbar", function(require, exports, module) {
	var exec = require('cordova/exec');

	var namedColors = {
	    "black": "#000000",
	    "darkGray": "#A9A9A9",
	    "lightGray": "#D3D3D3",
	    "white": "#FFFFFF",
	    "gray": "#808080",
	    "red": "#FF0000",
	    "green": "#00FF00",
	    "blue": "#0000FF",
	    "cyan": "#00FFFF",
	    "yellow": "#FFFF00",
	    "magenta": "#FF00FF",
	    "orange": "##FFA500",
	    "purple": "#800080",
	    "brown": "#A52A2A"
	};

	var StatusBar = {

	    isVisible: true,

	    overlaysWebView: function (doOverlay) {
	        exec(null, null, "StatusBar", "overlaysWebView", [doOverlay]);
	    },

	    styleDefault: function () {
	        // dark text ( to be used on a light background )
	        exec(null, null, "StatusBar", "styleDefault", []);
	    },

	    styleLightContent: function () {
	        // light text ( to be used on a dark background )
	        exec(null, null, "StatusBar", "styleLightContent", []);
	    },

	    styleBlackTranslucent: function () {
	        // #88000000 ? Apple says to use lightContent instead
	        exec(null, null, "StatusBar", "styleBlackTranslucent", []);
	    },

	    styleBlackOpaque: function () {
	        // #FF000000 ? Apple says to use lightContent instead
	        exec(null, null, "StatusBar", "styleBlackOpaque", []);
	    },

	    backgroundColorByName: function (colorname) {
	        return StatusBar.backgroundColorByHexString(namedColors[colorname]);
	    },

	    backgroundColorByHexString: function (hexString) {
	        if (hexString.charAt(0) !== "#") {
	            hexString = "#" + hexString;
	        }

	        if (hexString.length === 4) {
	            var split = hexString.split("");
	            hexString = "#" + split[1] + split[1] + split[2] + split[2] + split[3] + split[3];
	        }

	        exec(null, null, "StatusBar", "backgroundColorByHexString", [hexString]);
	    },

	    hide: function () {
	        exec(null, null, "StatusBar", "hide", []);
	        StatusBar.isVisible = false;
	    },

	    show: function () {
	        exec(null, null, "StatusBar", "show", []);
	        StatusBar.isVisible = true;
	    }

	};

	// prime it
	exec(function (res) {
	    if (typeof res == 'object') {
	        if (res.type == 'tap') {
	            cordova.fireWindowEvent('statusTap');
	        }
	    } else {
	        StatusBar.isVisible = res;
	    }
	}, null, "StatusBar", "_ready", []);

	module.exports = StatusBar;
})


define("cordova/plugin/statusbar/symbols", function(require, exports, module) {


var modulemapper = require('cordova/modulemapper');

modulemapper.clobbers('cordova/plugin/statusbar', 'window.StatusBar');

});


定义在cordova中。为了以后调用方便

   <gap:config-file platform="ios" parent="UIViewControllerBasedStatusBarAppearance">
        <false/>
    </gap:config-file>
    <gap:config-file platform="ios" parent="UIStatusBarStyle">
        <string>UIStatusBarStyleLightContent</string>
    </gap:config-file>

添加config 文件

<feature name="StatusBar">
        <param name="ios-package" value="CDVStatusBar" onload="true" />
 </feature>

添加插件调用

function checkstatubar(){
    window.StatusBar.overlaysWebView(false);
    window.StatusBar.backgroundColorByHexString('#2d7eca');
    window.StatusBar.styleLightContent();
}

写成一个公用函数
再需要的地方调用

已有 4 条评论
  1. 起重机配件

    学习了

    起重机配件 回复
  2. AngelFrdom

    导航栏的图片呢?无图不愿搞。交换友情链接可好不?我的博客 blog.frdom.me

    AngelFrdom 回复
  3. 厦门微信营销

    额 完全看不懂

    厦门微信营销 回复
  4. 灰常记忆

    不会这个。

    灰常记忆 回复
发表新评论