ios - How to change UITableViewCell Image to Circle in UITableView -


My code works for the most part.

  • The problem I have is to start the image as a square, and when I scroll to the table or refresh it then the cycle changes.

What am I missing?

Here's my code:

  cell .imageView.layer.cornerRadius = cell.imageView.frame.size.width / 2.0; Cell.imageView.layer.borderWidth = 3.0; Cell.imageView.layer.borderColor = [UIColor colorWithRed: 157.0 / 255.0 Green: 34.0 / 255.0 Blue: 53.0 / 255.0 Alpha: 1.0] .CGColor; Cell.imageView.clipsToBounds = Yes; NSDictionary * tweets = (auto-result) [indexPath.row]; Dispatch_queue_t queue = dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async (queue, ^ {NSString * imageString = [View valueForKeyPath: @ "user.profile_image_url"]; NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: imageString]] ;! if (imageData = null) {dispatch_async (Dispatch_get_main_queue (), ^ {cell.imageView.image = [UIImage imageWithData: imageData]; [cell setadleslayout;]}};}});  Edit   If I refresh to change the round or if I start scrolling the table then they change into goals   

Edit two

Another issue I see is the image change as I scroll.

How do I stop it?

In order for anyone to face this problem, then the solution is in solution

swift

  function table view (table view: UITableView, cellularright indexPath index: NSIndexPath) - & gt; UITableViewCell {var cell: ContactCellTableViewCell? = TableView.dequeueReusableCellWithIdentifier ("contactCell", forIndexPath: indexPath)? ContactCellTableViewCell Contact Bridesmaid: ContactStruct image = Search Results [indexPath.row] to newImage = resizeImage (image, toTheSize: CGSizeMake (70, 70)) var cellImageLayer: CALayer? = Cell? .imageView.layer cellimage layer !! CornerRadius = 35 cell image layer! .Misc Tubol = True Cell? .imageView.image = newImage returns cell! }  

As you can see, 35 hardcod is basically half of the image size which is 70 here and Here is the size function:

  function resizeImage (Image: UIImage, toSize Size: CGSize) - & gt; UIImage {var scale = CGFloat (max (size.width / image.size.width, Size.height / image.size.height)) var width: CGFloat = image.size.width * Scale Height: CGFloat = image.size .height * scale; Var RR: CGRCT = CGRactam (0, 0, width, height); UIGraphicsBeginImageContextWithOptions (size, false, 0); Image.drawInRect (RR) give new image = UIGraphicsGetImageFrintIsGateText () UIGRXIndImageContax (); Returns new image}  

Note: I am using a custom cell class below:

  import UIKit  
< P> Category ContactCellTableViewCell: UITableViewCell {

  @IBOutlet weak var name label: UILBL! @IBOutlet Weak Var Contact Image: UIImageView! @IBotatlet weak phone phone label: UILBL! AwakeFromNib () override function {super.awakeFromNib ()} setSelected function overrides (Selected: bool, animated: bool) {super.setSelected (selected animated: animated) configured scene // selected state}  < / Pre> 

}

Actually I took some time to take this one time. Images are round after scrolling for the first time, but now using this code, you are going to get round images within the cell from the beginning. Hope it helps someone.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -