根据图片长宽比例设置视图

#import "ZDHeaderView.h"

@implementation ZDHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        /* 添加子控件的代码*/
        CGSize size_header = [UIImage imageNamed:@"miss9"].size;
        _headerView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, size_header.height)];
        _headerView.image = [UIImage imageNamed:@"miss9"];
        [self addSubview:_headerView];
    }
    return self;
}
@end
  ZDHeaderView * zdView = [[ZDHeaderView alloc]init];
    zdView.frame = CGRectMake(0, 0, SCREEN_WIDTH, zdView.headerView.frame.size.height);
    _tableView.tableHeaderView = zdView;

你可能感兴趣的:(根据图片长宽比例设置视图)