我正在尝试设置单元格的附件视图,即UIButton
. 但它没有显示。
这是代码
UIButton *accessory = [UIButton buttonWithType:UIButtonTypeCustom];
[accessory setImage:[UIImage imageNamed:@"plus.png"] forState:UIControlStateNormal];
[cell setAccessoryView:accessory];
我正在尝试设置单元格的附件视图,即UIButton
. 但它没有显示。
这是代码
UIButton *accessory = [UIButton buttonWithType:UIButtonTypeCustom];
[accessory setImage:[UIImage imageNamed:@"plus.png"] forState:UIControlStateNormal];
[cell setAccessoryView:accessory];
调用[accessory sizeToFit];
根据图像调整其大小。
你需要像这样为这个配件设置一个框架
UIButton *accessory = [UIButton buttonWithType:UIButtonTypeCustom];
[accessory setImage:[UIImage imageNamed:@"plus.png"] forState:UIControlStateNormal];
//Set the accessory frame
accessory.frame = CGRectMake(0, 0, 100, 100);
UIView* accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 24, 50)];
UIImageView* accessoryViewImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
accessoryViewImage.center = CGPointMake(12, 25);
[accessoryView addSubview:accessoryViewImage];
[cell setAccessoryView:accessoryView];
[accessoryViewImage release];
[accessoryView release];
就这样做。