Ios 为什么阴影应用于我的视图中的文本而不是视图本身?
我有一个表格视图,里面有两个文本标签。我希望视图的轮廓带有阴影,但是,在我当前的代码中,只有文本有阴影。这是我的密码:Ios 为什么阴影应用于我的视图中的文本而不是视图本身?,ios,swift,uitableview,uiview,Ios,Swift,Uitableview,Uiview,我有一个表格视图,里面有两个文本标签。我希望视图的轮廓带有阴影,但是,在我当前的代码中,只有文本有阴影。这是我的密码: override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: K.reuseIdentifier, f
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: K.reuseIdentifier, for: indexPath) as! NoteTableViewCell
cell.titleLabel?.text = titleArray[indexPath.row]
cell.mainTextLabel?.text = noteArray[indexPath.row]
cell.titleLabel?.font = UIFont(name:"HelveticaNeue-Bold", size: 16.0)
cell.mainTextLabel?.font = UIFont(name:"HelveticaNeue", size: 14.0)
cell.cardView?.layer.shadowOpacity = 1
cell.cardView?.layer.shadowOffset = .zero
cell.cardView?.layer.shadowRadius = 1
cell.cardView?.layer.cornerRadius = 8
cell.cardView?.layer.shadowOffset = CGSize(width: 10,
height: 10)
return cell
}
NoteTableViewCell
class NoteTableViewCell: UITableViewCell {
@IBOutlet weak var cardView: UIView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var mainTextLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
以下是我的应用程序的屏幕截图:
我发现这是因为我没有为视图设置高度或宽度。在这样做之后,它正确地显示了你能显示
NoteTableViewCell
的代码吗?@aheze,我添加了代码你的cardView是透明的吗?@TomasJablonskis,我不这么认为,在它的属性检查器下,不透明复选框被标记了。是的,但是背景色是什么?