感谢您的所有回复。我已经解决了这个问题,代码在这里:
- (id)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code
[self setClipsToBounds:NO];
// selected background image view
if (self.selectedBgImageView == nil) {
// w 302 : h 50
self.selectedBgImageView = [[UIImageView alloc]
initWithFrame:CGRectMake(0, -5, 302, 50)];
}
[self.selectedBgImageView setContentMode:UIViewContentModeScaleToFill];
[self.contentView addSubview:self.selectedBgImageView];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
// child count label
[self.childCountLabel setBackgroundColor:
[UIColor colorWithPatternImage:
[UIImage imageNamed:@"btn_contacts_network_total"]]];
// selected background image view
if (self.indentationLevel % 2 == 0) {
[self.selectedBgImageView setImage:
[UIImage imageNamed:@"img_contacts_network_expand_box_tier1"]];
}
else {
[self.selectedBgImageView setImage:
[UIImage imageNamed:@"img_contacts_network_expand_box_tier2"]];
}
[self.selectedBgImageView setContentMode:UIViewContentModeScaleToFill];
// [self.con:selectedBgImageView];
}
在那里我发现设置框架是一个问题,我不知道这种奇怪的框架原点计算的原因。但不知何故,它对我有用,并且按照要求完美地工作。
如果有人知道这种行为背后的原因,请指导我。