How to resize a tableHeaderView of a UITableView?

后端 未结 19 2247
死守一世寂寞
死守一世寂寞 2020-11-29 16:14

I\'m having trouble resizing a tableHeaderView. It simple doesn\'t work.

1) Create a UITableView and UIView (100 x 320 px);

2) Set the UIView as tableHeaderV

19条回答
  •  感情败类
    2020-11-29 16:57

    I found the initWithFrame initializer of a UIView doesn't properly honor the rect I pass in. Hence, I did the following which worked perfectly:

     - (id)initWithFrame:(CGRect)aRect {
    
        CGRect frame = [[UIScreen mainScreen] applicationFrame];
    
        if ((self = [super initWithFrame:CGRectZero])) {
    
            // Ugly initialization behavior - initWithFrame will not properly honor the frame we pass
            self.frame = CGRectMake(0, 0, frame.size.width, 200);
    
            // ...
        }
    }
    

    The advantage of this is it is better encapsulated into your view code.

提交回复
热议问题