Make a NativeScript ListView Transparent on iOS

允我心安 提交于 2019-12-05 04:27:47

Don't forget to set the listview to transparent, seems to have a backgroundcolor itself

    ListView{
        background-color: transparent;
    }

Currently with NativeScript 2.4 the following works

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

And if you want to change the selection highlight color here is a simple approach, I have not tested performance but it works okay on an 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

Not sure if there are better ways to do this, but this is what worked for me with NativeScript 2.4 on iOS to both A) make the ListView background transparent, and B) change the color when an item is tapped:

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;
   }
};
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!