NativeScript ActionBar 不透明度
NativeScript ActionBar Opacity
我尝试更改操作栏的不透明度。为了进行测试,我尝试通过本机方法更改颜色,但这行不通。
我不明白为什么,UIAlert 等其他本机功能可以正常工作。
我没有错误或其他任何错误,只是操作栏看起来像这样:
我的目标是完全透明的,因为背景有渐变。
这是我的页面加载函数:
loaded(args){
let page = <Page>args.object;
page.bindingContext = appViewModel;
if (page.ios) {
var controller = frameModule.topmost().ios.controller;
var navigationBar = controller.navigationBar;
navigationBar.barTintColor = UIColor.blueColor();
}
}
感谢帮助
更新
我的代码:
var frameModule = require("ui/frame");
import {topmost} from "ui/frame";
import {Page} from "ui/page";
import {Observable, EventData} from "data/observable";
import {View} from "ui/core/view";
let appViewModel = new Observable({selectedPage: "dashboard"});
export abstract class BasePage {
//implement this function in the inheriting pages to set their specific binding context
abstract mainContentLoaded(args:EventData);
loaded(args){
let page = <Page>args.object;
page.bindingContext = appViewModel;
if (page.ios) {
frameModule.topmost().ios.navBarVisibility = "always";
page.ios.title = "Test Application";
var controller = frameModule.topmost().ios.controller;
var navBar = controller.navigationBar;
navBar.barTintColor = UIColor.redColor();
navBar.navigationBarHidden = false;
navBar.barStyle = UIBarStyle.UIBarStyleBlackTranslucent;
}
}
toggleDrawer(){
let page = <Page>topmost().currentPage;
let drawer = <any>page.getViewById("sidebar");
drawer.toggleDrawerState();
}
navigate(args){
let pageName = args.view.text.toLowerCase();
appViewModel.set("selectedPage", pageName);
topmost().navigate("modules/" + pageName + "/" + pageName);
}
}
我的xml:
<page
xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:drawer="nativescript-telerik-ui/sidedrawer"
xmlns:widgets="shared/widgets"
loaded="loaded">
<page.actionBar>
<action-bar>
<navigation-button icon="res://ic_menu" tap="toggleDrawer" ios:visibility="collapsed" />
<action-bar.actionItems>
<ios>
<action-item icon="res://ic_menu" ios.position="left" tap="toggleDrawer" />
</ios>
</action-bar.actionItems>
</action-bar>
</page.actionBar>
<drawer:rad-side-drawer id="sidebar">
<drawer:rad-side-drawer.mainContent>
</drawer:rad-side-drawer.mainContent>
<drawer:rad-side-drawer.drawerContent>
<widgets:drawer-content />
</drawer:rad-side-drawer.drawerContent>
</drawer:rad-side-drawer>
</page>
以下解决方案对我有用(iOS 9.3 with NativeScript 2.0.1)
if (page.ios) {
frameModule.topmost().ios.navBarVisibility = "always";
page.ios.title = "Test Application";
var controller = frameModule.topmost().ios.controller;
var navBar = controller.navigationBar;
navBar.barTintColor = UIColor.redColor();
navBar.navigationBarHidden = false;
navBar.barStyle = UIBarStyle.UIBarStyleBlackTranslucent;
}
我尝试更改操作栏的不透明度。为了进行测试,我尝试通过本机方法更改颜色,但这行不通。
我不明白为什么,UIAlert 等其他本机功能可以正常工作。 我没有错误或其他任何错误,只是操作栏看起来像这样:
我的目标是完全透明的,因为背景有渐变。
这是我的页面加载函数:
loaded(args){
let page = <Page>args.object;
page.bindingContext = appViewModel;
if (page.ios) {
var controller = frameModule.topmost().ios.controller;
var navigationBar = controller.navigationBar;
navigationBar.barTintColor = UIColor.blueColor();
}
}
感谢帮助
更新
我的代码:
var frameModule = require("ui/frame");
import {topmost} from "ui/frame";
import {Page} from "ui/page";
import {Observable, EventData} from "data/observable";
import {View} from "ui/core/view";
let appViewModel = new Observable({selectedPage: "dashboard"});
export abstract class BasePage {
//implement this function in the inheriting pages to set their specific binding context
abstract mainContentLoaded(args:EventData);
loaded(args){
let page = <Page>args.object;
page.bindingContext = appViewModel;
if (page.ios) {
frameModule.topmost().ios.navBarVisibility = "always";
page.ios.title = "Test Application";
var controller = frameModule.topmost().ios.controller;
var navBar = controller.navigationBar;
navBar.barTintColor = UIColor.redColor();
navBar.navigationBarHidden = false;
navBar.barStyle = UIBarStyle.UIBarStyleBlackTranslucent;
}
}
toggleDrawer(){
let page = <Page>topmost().currentPage;
let drawer = <any>page.getViewById("sidebar");
drawer.toggleDrawerState();
}
navigate(args){
let pageName = args.view.text.toLowerCase();
appViewModel.set("selectedPage", pageName);
topmost().navigate("modules/" + pageName + "/" + pageName);
}
}
我的xml:
<page
xmlns="http://schemas.nativescript.org/tns.xsd"
xmlns:drawer="nativescript-telerik-ui/sidedrawer"
xmlns:widgets="shared/widgets"
loaded="loaded">
<page.actionBar>
<action-bar>
<navigation-button icon="res://ic_menu" tap="toggleDrawer" ios:visibility="collapsed" />
<action-bar.actionItems>
<ios>
<action-item icon="res://ic_menu" ios.position="left" tap="toggleDrawer" />
</ios>
</action-bar.actionItems>
</action-bar>
</page.actionBar>
<drawer:rad-side-drawer id="sidebar">
<drawer:rad-side-drawer.mainContent>
</drawer:rad-side-drawer.mainContent>
<drawer:rad-side-drawer.drawerContent>
<widgets:drawer-content />
</drawer:rad-side-drawer.drawerContent>
</drawer:rad-side-drawer>
</page>
以下解决方案对我有用(iOS 9.3 with NativeScript 2.0.1)
if (page.ios) {
frameModule.topmost().ios.navBarVisibility = "always";
page.ios.title = "Test Application";
var controller = frameModule.topmost().ios.controller;
var navBar = controller.navigationBar;
navBar.barTintColor = UIColor.redColor();
navBar.navigationBarHidden = false;
navBar.barStyle = UIBarStyle.UIBarStyleBlackTranslucent;
}