RN的stylesheet的屬性及方法


屬性:hairlineWidth: 自適應不同設備生成一條線

var styles = StyleSheet.create({
  separator: {
    borderBottomColor: '#bbb',
    borderBottomWidth: StyleSheet.hairlineWidth,
  },
});

屬性:adsoluteFill: 

const styles = StyleSheet.create({
  wrapper: {
    ...StyleSheet.absoluteFill,
    top: 10,
    backgroundColor: 'transparent',
  },
});

相當於以下代碼的縮寫:

position: 'absolute',
left: 0, 
right: 0, 
top: 0, 
bottom: 0

 方法:create: 根據對象創建樣式表

StyleSheet.create({
   textColor: {
       color: #000 
   } 
})

方法:flatten: 可以把樣式對象的數組整合成一個樣式對象,重復的樣式屬性以后一個為准

var styles = StyleSheet.create({
  listItem: {
    flex: 1,
    fontSize: 16,
    color: 'white',
  },
  selectedListItem: {
    color: 'green',
  },
});

console.log(StyleSheet.flatten([styles.listItem, styles.selectedListItem]));
// returns { flex: 1, fontSize: 16, color: 'green' }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM