I would like to set a custom image for all the UITableViewCell accessory view in my app. 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. Here's an example implementation:
.h:
- (void)setAccessoryViewImage:(UIImage *)image UI_APPEARANCE_SELECTOR;
.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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.