Take the 2-minute tour ×

I have CustomCellView which is custom view for cell in tableview. I have UIButton in xib and set it's default frame in xib.

In MainViewController (viewDidLoad)

// Get nib for custom cell
UINib *nib = [UINib nibWithNibName:@"CustomFeedCell" bundle:nil];
[self.mainTableView registerNib:nib forCellReuseIdentifier:@"CustomFeedCell"];

In cellForRow...

CustomFeedCell *cell = [self.mainTableView dequeueReusableCellWithIdentifier:@"CustomFeedCell"];

// here i need to set UIButton frame (height) depending on image height.
// I have tried diferent ways and it always return height set in CustomCellView xib
share|improve this question
add comment

2 Answers

If you want to create buttons, images etc in UIView dynamically, you have to use viewDidLoad: method and do not use xibs.

share|improve this answer
add comment

Ok so what I am understanding from your question is you are having problem setting the dynamic height of a button present in your tableview cell. It sometimes might be more then the height of the cell and sometimes quiet less then height of the cell. And you want to adjust it accordingly. Correct ?

If thats your problem then you can set height of your each tableview cell in its delegate tableView:heightForRowAtIndexPath:


    return [indexPath row] * 20; // your desired height

Hope this solves your problem.

share|improve this answer
add comment

Your Answer


