【发布时间】:2015-05-05 13:23:11
【问题描述】:
这个问题在这里已经有了答案:
(1)How to fix UITableView separator on iOS 7?
我遇到了和iOS: UIImageView changes with change in UITableView.rowHeight, how to avoid?描述的一样的问题,当然在SO中,有很多这样的Q/As,我尝试了很多答案,但都没有得到正确的结果:
(1) 在...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;
我得到了以下信息:
(2) 我试过上面的answer: 基于(1)的代码,我添加了:
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;
我又得到了一张奇怪的照片:
追加:
我希望我得到以下结果:
图标下方是一条实线
【问题讨论】:
-
注意:要更改行高,您必须使用 UITableViewDelegate 协议的方法 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath。
-
行高是关键问题,我可以在
storyboard中将其改大,比如50 或更大,当然tableView.rowHeight = 43;也可以为我工作,无论我采用哪种方式用于改变高度,我得到了相同的结果 -
是你真正的代码还是你使用 UITableViewCell 的子类?
-
@stosha,你的意思是,也许我的图标太大了?
-
试试这样的:tableView.rowHeight = 32.0f; UIImage* im = [UIImage imageNamed: @"news"]; cell.imageView.frame = CGRectMake(0, 0, 32, 32);单元格.imageView.image = im;而不是 (2)
标签: ios objective-c iphone uitableview uiimageview