I have problem with overlapping labels in custom cells. Here are init and layout methods for this cells:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
self.img = [[[UIImageView alloc] init] autorelease];
[self.contentView addSubview:self.img];
self.p = [[[UILabel alloc] init] autorelease];
[self.p setTextAlignment:UITextAlignmentCenter];
[self.p setFont:[UIFont fontWithName:@"Helvetica" size:10.0]];
[self.p setLineBreakMode:UILineBreakModeTailTruncation];
[self.p setNumberOfLines:1];
[self.p setTextColor:[UIColor whiteColor]];
[self.p setBackgroundColor:[UIColor redColor]];
[self.p setText:@"PREMIERA"];
[self.contentView addSubview:self.p];
self.g = [[[UILabel alloc] init] autorelease];
[self.g setTextAlignment:UITextAlignmentLeft];
[self.g setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12.0]];
[self.g setLineBreakMode:UILineBreakModeTailTruncation];
[self.g setNumberOfLines:1];
[self.contentView addSubview:self.g];
self.t = [[[UILabel alloc] init] autorelease];
[self.t setTextAlignment:UITextAlignmentLeft];
[self.t setFont:[UIFont fontWithName:@"Helvetica-Bold" size:14.0]];
[self.t setMinimumFontSize:12.0f];
[self.t setAdjustsFontSizeToFitWidth:YES];
[self.t setLineBreakMode:UILineBreakModeTailTruncation];
[self.t setNumberOfLines:1];
[self.contentView addSubview:self.t];
self.o = [[[UILabel alloc] init] autorelease];
[self.o setTextAlignment:UITextAlignmentLeft];
[self.o setFont:[UIFont fontWithName:@"Helvetica" size:12.0]];
[self.o setLineBreakMode:UILineBreakModeTailTruncation];
[self.o setNumberOfLines:1];
[self.contentView addSubview:self.o];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.img.frame = CGRectMake(0, 0, 40, 60);
self.p.frame = CGRectMake(0, 0, 0, 0);
self.g.frame = CGRectMake(0, 0, 0, 0);
self.t.frame = CGRectMake(0, 0, 0, 0);
self.o.frame = CGRectMake(0, 0, 0, 0);
CGSize pSize = CGSizeMake(0, 0);
CGSize gSize = CGSizeMake(0, 0);
CGSize tSize = [self.t.text sizeWithFont:self.t.font constrainedToSize:CGSizeMake(230, 16) lineBreakMode:self.t.lineBreakMode];
CGSize oSize = [self.o.text sizeWithFont:self.o.font constrainedToSize:CGSizeMake(230, 16) lineBreakMode:self.o.lineBreakMode];
if (self.jestPremiera)
{
pSize = [self.p.text sizeWithFont:self.p.font constrainedToSize:CGSizeMake(60, 16) lineBreakMode:self.p.lineBreakMode];
gSize = [self.g.text sizeWithFont:self.g.font constrainedToSize:CGSizeMake(175, 16) lineBreakMode:self.g.lineBreakMode];
self.p.frame = CGRectMake(50, 5, 60, pSize.height);
self.p.hidden = NO;
self.g.frame = CGRectMake(115, 5, 175, gSize.height);
}
else
{
gSize = [self.g.text sizeWithFont:self.g.font constrainedToSize:CGSizeMake(230, 16) lineBreakMode:self.g.lineBreakMode];
self.p.hidden = YES;
self.g.frame = CGRectMake(50, 5, 230, gSize.height);
}
self.t.frame = CGRectMake(50, 5 + gSize.height, 230, tSize.height);
self.o.frame = CGRectMake(50, 5 + gSize.height + tSize.height, 230, oSize.height);
}
通常,这项工作(仅限在3G装置上)按样进行:。
谁能告诉我这种行为的原因是什么,我能做些什么?