func tableVIEw(_ tableVIEw: UItableVIEw,willdisplay cell: UItableVIEwCell,forRowAt indexPath: IndexPath){ cell.backgroundcolor = UIcolor.clear cell.contentVIEw.backgroundcolor = UIcolor.clear let whiteRoundedVIEw : UIVIEw = UIVIEw(frame: CGRect(x:10,y: 5,wIDth: self.vIEw.frame.size.wIDth - 20,height: 214)) whiteRoundedVIEw.layer.masksToBounds = false whiteRoundedVIEw.layer.cornerRadius = 5.0 whiteRoundedVIEw.layer.shadowOffset = CGSize(wIDth: -1,height: 1) whiteRoundedVIEw.layer.borderWIDth = 2 cell.contentVIEw.addSubvIEw(whiteRoundedVIEw) cell.contentVIEw.sendSubvIEw(toBack: whiteRoundedVIEw) if stock[indexPath.row] == "inStock" { whiteRoundedVIEw.layer.bordercolor = UIcolor.red.cgcolor } else { whiteRoundedVIEw.layer.bordercolor = UIcolor.green.cgcolor }}解决方法 尝试将代码移动到像这样的cellForRowAt方法
cell.layer.masksToBounds = truecell.layer.cornerRadius = 5cell.layer.borderWIDth = 2cell.layer.shadowOffset = CGSize(wIDth: -1,height: 1)let bordercolor: UIcolor = (stock[indexPath.row] == "inStock") ? .red : .greencell.layer.bordercolor = bordercolor.cgcolor总结
以上是内存溢出为你收集整理的Swift根据数据更改tableviewcell边框颜色全部内容,希望文章能够帮你解决Swift根据数据更改tableviewcell边框颜色所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)