Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a standard accessory view be in a different position within a UITableViewCell?

I want my accessory to be in a slightly different place than normal. Is it possible? This code has no effect:

cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator; cell.accessoryView.frame = CGRectMake(5.0, 5.0, 5.0, 5.0); 
like image 668
cannyboy Avatar asked May 20 '10 16:05

cannyboy


2 Answers

No, you cannot move where the accessory view is. As an alternative you can add a subview like the following;

[cell.contentView addSubview:aView]; 

Also, by setting the accessoryView property equal to something, the accessoryType value is ignored.

like image 98
rickharrison Avatar answered Sep 29 '22 04:09

rickharrison


There is a way to move default accessoryView, but it's pretty hacky. So it might stop working one day when a new SDK arrives.

Use at your own risk (this code snippet moves any accessoryView 8 pixels to the left. Call [self positionAccessoryView]; from inside the -(void)layoutSubviews method of the desired UITableViewCell subclass):

- (void)layoutSubviews {     [super layoutSubviews];     [self positionAccessoryView]; }  - (void)positionAccessoryView {     UIView *accessory = nil;     if (self.accessoryView) {         accessory = self.accessoryView;     } else if (self.accessoryType != UITableViewCellAccessoryNone) {         for (UIView *subview in self.subviews) {             if (subview != self.textLabel &&                 subview != self.detailTextLabel &&                 subview != self.backgroundView &&                 subview != self.contentView &&                 subview != self.selectedBackgroundView &&                 subview != self.imageView &&                 [subview isKindOfClass:[UIButton class]]) {                 accessory = subview;                 break;             }         }     }      CGRect r = accessory.frame;     r.origin.x -= 8;     accessory.frame = r; } 
like image 35
Alexey Avatar answered Sep 29 '22 02:09

Alexey