代码之家  ›  专栏  ›  技术社区  ›  Loki

Nativescript-将边框顶部添加到操作栏

  •  0
  • Loki  · 技术社区  · 8 年前

    大家好,我有个问题, 我想在操作栏顶部添加红色边框 这是我的密码-

    <ActionBar class=" border-top"  title="" loaded="loaded" >
        <NavigationButton ></NavigationButton>
        <ActionBar.actionItems  >
            <ActionItem ios.position="right" >
                <ActionItem.actionView>
                    <AbsoluteLayout >
                    <Label text="&#xf145;" class="action-item gray" />
                    </AbsoluteLayout>
                </ActionItem.actionView>
            </ActionItem>
            <ActionItem ios.position="right" >
                <ActionItem.actionView>
                    <AbsoluteLayout  class="{{ selectedPage ==='contacts' ? 'higlight-menu-item':'' }}">
                        <Label text="&#xf0c0;" class="action-item gray" />
                    </AbsoluteLayout>
                </ActionItem.actionView>
            </ActionItem>
        </ActionBar.actionItems>
    </ActionBar>
    

    在我的应用程序中。css

    .border-top {
      border-top-color:#ec295f;
        border-top-width:2;
    }
    

    这在Android设备上运行良好,但在IOS上没有显示 似乎没有现成的IOS解决方案 我在这里发现了问题 https://github.com/NativeScript/NativeScript/issues/5395

    https://github.com/NativeScript/NativeScript/issues/2470#issuecomment-233555881

    但我不知道怎么写?? 我尝试了几天,但没有解决方案,有人能帮我一点吗??

    1 回复  |  直到 8 年前
        1
  •  0
  •   Loki    8 年前

    Nativescript中没有解决方案,所以我必须访问IOS的本机方法并编写自己的解决方案。 以下是我的解决方案:

    var colorModule = require("color");
    var red = new colorModule.Color("#ec295f");
    const frameModule = require('ui/frame');
    
    
    if (frameModule.topmost().ios) {
            let controller = frameModule.topmost().ios.controller;
            let navBar = controller.navigationBar;
            let border = new UIView(CGRectMake(0, 1, navBar.frame.size.width, 2));
            border.backgroundColor = UIColor(red.ios);
            border.opaque = true;
            navBar.addSubview(border);
        }
    

    希望对某人有所帮助:)

    推荐文章