【问题标题】:Row backbround gets cut off行背景被切断
【发布时间】:2011-08-22 09:10:58
【问题描述】:

我有一张桌子.. 我尝试在每一行中显示此图像。

但是当我这样做时

cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"BlueLong.png"]];

结果是这样的..

第一行是正确的..但之后它就像图像的上边被切割了..? 我该如何解决这个问题?

已经好了!

【问题讨论】:

标签: objective-c ios ipad uitableview


【解决方案1】:

stretch.png - 这是您的图像缩小为阴影和形状

cell.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"stretch.png"] stretchableImageWithLeftCapWidth:21.0 topCapHeight:15.0]];

21 和 15 是图像的中心,大小为 42x31 像素

编辑:这应该可以工作

cell.backgroundColor = [UIColor clearColor];
cell.backgroundView = [[UIImageView alloc] initWithImage:[[UIImage imageNamed:@"stretch.png"] stretchableImageWithLeftCapWidth:21 topCapHeight:15]];

【讨论】:

  • 这不是一个把戏;)结果是什么?你用过我的图片吗?
  • 没有结果,因为什么也没发生 :D,我正在使用这个 cell.backgroundColor = [UIColor colorWithPatternImage:[[UIImage imageNamed:@"BlueLong.png"] stretchableImageWithLeftCapWidth:550 topCapHeight:79]];图片尺寸为 1100, 158
  • 图片太大了,不能缩小,只能放大,所以你需要剪掉所有不需要的东西,就像你在我的图片中看到的那样,只有阴影和形状离开了。所以用我的图片试试
  • 如果我尝试使用你的图像,图像不会拉伸,而是像这样复制它们。 imageshack.us/photo/my-images/27/schermafbeelding2011082u.png,也许我忘记更改属性了?
【解决方案2】:

您是否尝试过实现 UITableViewDelegate 方法(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 来告诉行它应该有多高?

【讨论】:

  • 是的,我做到了,但这与它无关,因为您可以看到第三行和最后一行的高度与其他行不同。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-25
  • 2015-01-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-29
相关资源
最近更新 更多