Created
June 11, 2014 16:46
-
-
Save azamsharp/6c1530b681e613b5711c to your computer and use it in GitHub Desktop.
Easily Creating Blur Effect for UITableViewCells Using iOS 8 VisualEffectView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// FlowersTableViewController.swift | |
// Flowers++ | |
// | |
// Created by Mohammad Azam on 6/6/14. | |
// Copyright (c) 2014 AzamSharp Consulting LLC. All rights reserved. | |
// www.azamsharp.com | |
// www.youtube.com/azamsharp | |
import UIKit | |
class FlowersTableViewController: UITableViewController { | |
var flowers :NSMutableArray = NSMutableArray() | |
init(style: UITableViewStyle) { | |
super.init(style: style) | |
// Custom initialization | |
} | |
init(coder aDecoder: NSCoder!) | |
{ | |
super.init(coder: aDecoder) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
var rose :Flower = Flower() | |
rose.name = "Roses" | |
rose.backgroundImage = "A-rose-is-a-rose-roses-20581060-2256-1496.jpg" | |
var shrub :Flower = Flower() | |
shrub.name = "Shrubs" | |
shrub.backgroundImage = "shrub-garden-green-mulch.jpg" | |
flowers.addObject(rose) | |
flowers.addObject(shrub) | |
self.tableView.reloadData() | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
// #pragma mark - Table view data source | |
override func numberOfSectionsInTableView(tableView: UITableView?) -> Int { | |
return 1 | |
} | |
override func tableView(tableView: UITableView?, numberOfRowsInSection section: Int) -> Int { | |
return flowers.count | |
} | |
override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? | |
{ | |
println("The indexPath code is \(indexPath!.row)") | |
let cell = tableView!.dequeueReusableCellWithIdentifier("FlowerTableViewCell", forIndexPath: indexPath) as FlowerTableViewCell | |
let flower = flowers[indexPath!.row] as Flower | |
let backgroundImageView = UIImageView(image: UIImage(named: flower.backgroundImage)) | |
cell.backgroundView = backgroundImageView | |
var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light)) as UIVisualEffectView | |
visualEffectView.frame = CGRectMake(0, 0, cell.bounds.width, cell.bounds.height) | |
backgroundImageView.addSubview(visualEffectView) | |
cell.textLabel.text = flower.name | |
cell.textLabel.textColor = UIColor.whiteColor() | |
cell.textLabel.backgroundColor = UIColor.clearColor() | |
return cell | |
} | |
/* | |
// Override to support conditional editing of the table view. | |
override func tableView(tableView: UITableView?, canEditRowAtIndexPath indexPath: NSIndexPath?) -> Bool { | |
// Return NO if you do not want the specified item to be editable. | |
return true | |
} | |
*/ | |
/* | |
// Override to support editing the table view. | |
override func tableView(tableView: UITableView?, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath?) { | |
if editingStyle == .Delete { | |
// Delete the row from the data source | |
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) | |
} else if editingStyle == .Insert { | |
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view | |
} | |
} | |
*/ | |
/* | |
// Override to support rearranging the table view. | |
override func tableView(tableView: UITableView?, moveRowAtIndexPath fromIndexPath: NSIndexPath?, toIndexPath: NSIndexPath?) { | |
} | |
*/ | |
/* | |
// Override to support conditional rearranging of the table view. | |
override func tableView(tableView: UITableView?, canMoveRowAtIndexPath indexPath: NSIndexPath?) -> Bool { | |
// Return NO if you do not want the item to be re-orderable. | |
return true | |
} | |
*/ | |
/* | |
// #pragma mark - Navigation | |
// In a storyboard-based application, you will often want to do a little preparation before navigation | |
override func prepareForSegue(segue: UIStoryboardSegue?, sender: AnyObject?) { | |
// Get the new view controller using [segue destinationViewController]. | |
// Pass the selected object to the new view controller. | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment