2016-03-31 16 views
5

Próbuję uzyskać przejrzystość NativeScript <ListView> w systemie iOS i nie udało mi się. Znalazłem stary wątek na temat na https://groups.google.com/forum/#!topic/nativescript/-MIWcQo-l6k, ale kiedy próbuję rozwiązanie to nie działa dla mnie. Oto mój pełny kod:Tworzenie przejrzystego widoku listy NativeScript na iOS

/* 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); 
    } 
} 

Każda pomoc będzie mile widziane. Dzięki!

Odpowiedz

9

Nie zapomnij ustawić ListView z przejrzystymi, wydaje się mieć backgroundColor sam

ListView{ 
     background-color: transparent; 
    } 
+1

Aby wyjaśnić przyszłym pracownikom Google, użyj tego + kodu "itemLoading" TJ, aby zniknęło tło ListView iOS. Potrzebujesz obu. – Todd

1

Obecnie z NativeScript 2.4 następujące prace

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

A jeśli chcesz zmienić wybór podświetl kolor tutaj jest proste podejście, nie testowałem wydajności, ale działa poprawnie na iPhonie 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 
+0

Jak mogę uzyskać dostęp do UITableViewCellSelectionStyleNone? Pochodzi z UITableViewCellSelectionStyle, ale nie mogę znaleźć odpowiedniego importu z Webstorm. Dzięki za odpowiedź. Z poważaniem, David. –

0

Nie jestem pewien, czy są na to lepsze sposoby, ale to działało dla mnie z NativeScript 2.4 na iOS zarówno dla A) uczynić tło ListView przezroczystym, jak i B) zmienić kolor, gdy element jest dotknięty:

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; 
    } 
};