【问题标题】:Why is the shadow being applied to the text in my view and not the view itself?为什么阴影应用于我视图中的文本而不是视图本身?
【发布时间】:2021-05-21 18:20:37
【问题描述】:

我有一个填充了 2 个文本标签的表格视图。我希望用阴影勾勒出视图,但是,使用我当前的代码,只有文本有阴影。这是我的代码:

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,我不这么认为,在其属性检查器下标记了不透明复选框。
  • 是的,但是背景颜色是什么?

标签: ios swift uitableview uiview


【解决方案1】:

我发现这是因为我没有为视图设置高度或宽度。这样做后它显示正确

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-21
    • 2020-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-03
    相关资源
    最近更新 更多