【问题标题】:Make a NativeScript ListView Transparent on iOS在 iOS 上使 NativeScript ListView 透明
【发布时间】:2016-03-31 13:44:57
【问题描述】:

我试图让 NativeScript <ListView> 在 iOS 上透明,但我失败了。我在https://groups.google.com/forum/#!topic/nativescript/-MIWcQo-l6k 找到了一个关于该主题的旧线程,但是当我尝试该解决方案时,它对我不起作用。这是我的完整代码:

/* app.css */
Page { background-color: black; }

<!-- main-page.xml -->
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="loaded">
  <ListView id="list-view" items="{{ items }}" itemLoading="itemLoading">
    <ListView.itemTemplate>
      <Label text="{{ name }}" />
    </ListView.itemTemplate>
  </ListView>
</Page>

// main-page.js
var ios = require("utils/utils");
var Observable = require("data/observable").Observable;
var ObservableArray = require("data/observable-array").ObservableArray;

var page;
var items = new ObservableArray([]);
var pageData = new Observable();

exports.loaded = function(args) {
  page = args.object;
  page.bindingContext = pageData;

  // Toss a few numbers in the list for testing
  items.push({ name: "1" });
  items.push({ name: "2" });
  items.push({ name: "3" });

  pageData.set("items", items);
};

exports.itemLoading = function(args) {
  var cell = args.ios;
  if (cell) {
    // Use ios.getter for iOS 9/10 API compatibility
    cell.backgroundColor = ios.getter(UIColor.clearColor);
  }
}

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: nativescript


    【解决方案1】:

    别忘了把listview设置为透明,好像本身就有背景色

        ListView{
            background-color: transparent;
        }
    

    【讨论】:

    • 为了澄清未来的 Google 员工,请使用此 + TJ 的 itemLoading 代码使 iOS ListView 背景消失。两者都需要。
    【解决方案2】:

    目前使用 NativeScript 2.4 以下作品

    var cell = args.ios;
    if (cell) {
      cell.selectionStyle = UITableViewCellSelectionStyleNone
    }
    

    如果你想在这里更改选择突出显示颜色是一种简单的方法,我没有测试过性能,但它在 iPhone 6 上可以正常工作。

    import { Color } from 'color';
    cell.selectedBackgroundView = UIView.alloc().initWithFrame(CGRectMake(0, 0, 0, 0));
    let blue = new Color('#3489db');
    cell.selectedBackgroundView.backgroundColor = blue.ios
    

    【讨论】:

    • 如何访问 UITableViewCellSelectionStyleNone?它来自 UITableViewCellSelectionStyle,但我无法使用 Webstorm 找到合适的导入。感谢您的回答。亲切的问候,大卫。
    【解决方案3】:

    不确定是否有更好的方法来做到这一点,但这对我来说是在 iOS 上使用 NativeScript 2.4 的方法 A)使 ListView 背景透明,以及 B)在点击项目时更改颜色:

    let lvItemLoading = (args) => {
       let cell = args.ios;
       if (cell) {
          // Make the iOS listview background transparent
          cell.backgroundColor = ios.getter(cell, UIColor.clearColor);
    
          // Create new background view for selected state
          let bgSelectedView = UIView.alloc().init();
          bgSelectedView.backgroundColor = new Color("#777777").ios;
          bgSelectedView.layer.masksToBounds = true;
          cell.selectedBackgroundView = bgSelectedView;
       }
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多