reactNative 渐变色背景+圆角 ios不兼容问题

809 阅读1分钟

一 、RN里面想实现渐变色背景+圆角效果,如图

image.png

二、 发现RN要实现渐变背景,需要linear-gradient 组件来实现,然后添加圆角之后

圆角样式
        borderBottomLeftRadius:JDDevice.getRpx(16),
        borderTopRightRadius:JDDevice.getRpx(16),

安卓可以正常显示渐变+圆角,但是IOS不能显示圆角,后发现,添加属性overflow:hidden之后,IOS可以展示圆角

  borderBottomLeftRadius:JDDevice.getRpx(16),
  borderTopRightRadius:JDDevice.getRpx(16),
  overflow: 'hidden'

因为ios原生里默认子view超过父视图的部分是显示的,如果想要不显示得设置父元素超出不显示,即overflow:hidden