Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

iphone - How can I change a cell's textLabel frame?

I've tried nearly everything, but I just can't seem to move the cell.textLabel property down a little bit. I've attached a screenshot below and I've tried nearly everything I could find.

I've tried changing the .frame property directly, attempted at modifying if via using the "- (void)tableView:(UITableView *)tableView willDisplayCell" method". I've also tried allocating a custom label. I could move the custom label, but it wouldn't go into separate lines like the original textLabel. I just need to move the pictured multi line label a bit down.

Any help is appreciated!

enter image description here

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

override layoutSubviews for your UITableViewCell...

- (void)layoutSubviews {
    [super layoutSubviews];

    CGSize size = self.bounds.size;
    CGRect frame = CGRectMake(4.0f, 4.0f, size.width, size.height); 
    self.textLabel.frame =  frame;
    self.textLabel.contentMode = UIViewContentModeScaleAspectFit;
}

or you can simply make your own UILabel object, and add it to cell.contentView as a subview.

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(4, 4, 30, 30)];
[cell.contentView addSubview:label];
[label release];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...