UITableViewCell 自定义(拉伸)背景使用 UIAppearance



我正在尝试通过UIAppearance来定制UITableViewCell,就像我实现自定义UINavigationBar(ruby运动语法)一样:

bg = UIImage.imageNamed("cell_bg.png").resizableImageWithCapInsets(UIEdgeInsetsMake(0,13,0,13))
UITableViewCell.appearance.setBackgroundImage(bg, forState:UIControlStateNormal, barMetrics:UIBarMetricsDefault)

但 setBackgroundImage 未定义,setBackgroundView 和 setBackgroundViewImage...UITableViewCell符合UIAppearanceContainer,所以我不应该使用其中一个吗?

谢谢

符合UIAppearanceContainer并不意味着您可以设置任何您喜欢的外观,它只是意味着它将提供一个外观代理。据我所知,UITableViewCell 没有任何内置的 UIAppearance 方法。

为了满足您的需求,请尝试使用可拉伸图像创建 UIImageView,并将其设置为单元格的backgroundView

最新更新