简体   繁体   English

使用UIAppearance代理自定义UITableViewCell

[英]Custom UITableViewCell using UIAppearance proxy

I would like to set a custom image for all the UITableViewCell accessory view in my app. 我想为我的应用程序中的所有UITableViewCell附件视图设置自定义图像。 I've tried using this code: 我尝试使用此代码:

[[UITableViewCell appearance] setAccessoryView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"table-arrow.png"]]];

but it doesn't work. 但这不起作用。

Any idea? 任何想法?

Try creating custom appearance selector in UITableViewCell category. 尝试在UITableViewCell类别中创建自定义外观选择器。 Here's an example implementation: 这是一个示例实现:

.h: 。H:

- (void)setAccessoryViewImage:(UIImage *)image UI_APPEARANCE_SELECTOR;

.m: .M:

- (void)setAccessoryViewImage:(UIImage *)image {
    self.accessoryView = [[UIImageView alloc] initWithImage:image];
}

And than you can configure all your cells using proxy object: 然后,您可以使用代理对象配置所有单元:

[[UITableViewCell appearance] setAccessoryViewImage:[UIImage imageNamed:@"table-arrow.png"]];

// try this // 尝试这个

   cell.accessoryType = UITableViewCellAccessoryNone;
   UIImageView *imgArrow = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 10, 15)] ;
   imgArrow.image = [UIImage imageNamed:@"table-arrow.png"];
   cell.accessoryView = imgArrow;
   [imgArrow release];
   imgArrow = nil;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM