1

Мне нужно сделать тень под конкретной UITableViewCell, я это сделал, но у меня есть проблема, когда я делаю scroll вниз то все отображается правильно, но когда я делаю scroll вверх то, у ячейки которая имеет тень, эта тень отображается не под ячейкой, а над нею. Как я могу это исправить?

        func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier(cellReuseIdentifier, forIndexPath: indexPath) as! LifelineLeaderboardTableViewCell

        // Configure the cell...
        let lifelineRecentModel = users[indexPath.row]

        cell.clipsToBounds = false
        if let currentUserID = DBHelper.instance.mainUserId {
            if lifelineRecentModel.user.id == currentUserID {
                cell.setupUserNumberLabelTextColor(true)
                cell.showBlueLineView(true)
//                cell.showShadow(true)
                let shadowView = UIView(frame: cell.bounds)

                let shadowFrame = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: cell.bounds.width, height: 90))
                let shadowPath = UIBezierPath(rect: shadowFrame).CGPath
                let shadow = CAGradientLayer()

                shadow.shadowOpacity = 0.25
                shadow.shadowColor = UIColor.blackColor().CGColor
                shadow.shadowPath = shadowPath
                shadowView.layer.insertSublayer(shadow, atIndex: 0)
                cell.contentView.addSubview(shadowView)
            } else {
                cell.setupUserNumberLabelTextColor(false)
                cell.showBlueLineView(false)
                cell.showShadow(false)
            }
        } else {
            cell.setupUserNumberLabelTextColor(false)
            cell.showBlueLineView(false)
            cell.showShadow(false)
        } 

        return cell
    }

1 ответ 1

2

Ты каждый раз кладешь shadowView поверх всех вьюшек. Замени метод addSubview в строчке cell.contentView.addSubview(shadowView) на метод insertSubview:shadowView atIndex:0 или на insertSubview:shadowView belowSubview: <cell.firstLabel>;

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.