mercredi 4 mars 2015

iOS: UIImageView in UITableViewCell can be changed? why I was failed?

I met the same question as iOS: UIImageView changes with change in UITableView.rowHeight, how to avoid? described, of course, in SO, there were many Q/As like this, and I tried many answers, but I did not get the right result:


(1) when in ...cellForRowAtIndexPath...:



NSString *CellIdentifier = [menuItems objectAtIndex:indexPath.row];
NSString *CellLabel = [menuLabels objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
cell.textLabel.text = CellLabel;
tableView.rowHeight = 43;

UIImage* im = [UIImage imageNamed: @"news"];
cell.imageView.image = im;


I got the following: enter image description here


(2) I tried the above answer: based on (1)'s code, I added:



UIGraphicsBeginImageContextWithOptions(CGSizeMake(32,32), YES, 0);
[im drawInRect:CGRectMake(0,0,32,32)];
UIImage* im2 = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
cell.imageView.image = im2;
cell.imageView.contentMode = UIViewContentModeCenter;


I got another strange picture: enter image description here




Aucun commentaire:

Enregistrer un commentaire