【问题标题】:Using gradient background in UITableViewCell [duplicate]在 UITableViewCell 中使用渐变背景 [重复]
【发布时间】:2010-11-15 18:02:52
【问题描述】:

可能重复:
UITableViewCell with custom gradient background, with another gradient as highlight color

嘿,我正在尝试使用渐变作为我的 tableView 单元格的背景,我已经尝试使用此代码:

        UIView *view = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 100)] autorelease];
            CAGradientLayer *gradient = [CAGradientLayer layer];
            gradient.frame = view.bounds;
            gradient.colors = [NSArray arrayWithObjects:(id)[[UIColor blackColor] CGColor], (id)[[UIColor whiteColor] CGColor], nil];
            [view.layer insertSublayer:gradient atIndex:0];
            [cell setBackgroundView:view];

知道为什么这不能正常工作吗?

【问题讨论】:

  • 为什么同一个问题会在 12 小时内出现?
  • AppKit 只存在于 Cocoa 中。您正在使用 UIKit。另外,请描述它究竟是如何“无法正常工作”的。
  • vikingosegundo:标题相同,但问题不同,更具体。
  • 它不能正常工作的原因在于它不只是显示。
  • 好的,所以我看到它在我实际选择单元格并移动到下一个视图时显示了一会儿。它以某种方式显示在选定的状态。

标签: cocoa-touch ios uikit core-graphics quartz-graphics


【解决方案1】:

不要将视图直接添加到单元格中,将其添加到单元格的contentView。这将确保当方向发生时,调整大小会按预期发生,而不是一些搞砸的方式。这也将确保,在其他情况下,您可能在该视图中嵌入了一些其他视图(例如滚动视图),它实际上会流畅地滚动,等等。当它们被放置在它们所在的位置时,它们会按预期工作......期待。

【讨论】:

  • 但是当我尝试将视图作为背景视图时,它不会以某种方式显示出来:S 我不明白我做错了什么。
  • jer 指示您不要使用 backgroundView。使用内容视图。在 WWDC 视频中也提到过
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多