Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Use vibrancy effect in UITableViewCell like notification center.

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 727
    Comment on it

    1.   It is must to import “NoticationCenter” so that we can use “notificationCenterVibrancyEffect”

    import NotificationCenter

     

    2. At the time of cell selection do following code in delegate method of UITableView “didHighlightRowAtIndexPath”

    let selectedCell = tableView.cellForRowAtIndexPath(indexPath)! as! UITableViewCell
        var vibrancyEffect = UIVibrancyEffect()
        selectedCell.firstLable.textColor = UIColor.whiteColor()
        selectedCell.secondLable.textColor = UIColor.whiteColor()
        vibrancyEffect = UIVibrancyEffect.notificationCenterVibrancyEffect()
        let selectBackgroundView = UIVisualEffectView(effect: vibrancyEffect)
        selectBackgroundView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        selectBackgroundView.frame = selectedCell.contentView.bounds
        let view = UIView(frame: selectBackgroundView.bounds)
        view.backgroundColor = UIColor(white: 0.1, alpha: 0.5)
        view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
        selectedCell.contentView.backgroundColor = UIColor(white: 0.1, alpha: 0.5)
        selectBackgroundView.contentView.addSubview(view)
        selectedCell.contentView.addSubview(selectBackgroundView)
        selectBackgroundView.tag = 100        // we are giving tag here , so that we can recognize particular cell while deselecting it.

     

    3. While deselecting cell put following line of code in delegate method of UITableView “didUnhighlightRowAtIndexPath”

     let selectedCell = tableView.cellForRowAtIndexPath(indexPath)! as! UITableViewCell
        selectedCell.firstLable.textColor = UIColor.darkGrayColor()
        selectedCell.secondLable.textColor = UIColor.darkGrayColor()
        selectedCell.contentView.viewWithTag(100)?.removeFromSuperview()     //from the tag we had given before we can recognize the cell.
        selectedCell.contentView.backgroundColor = .clearColor()

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: