custum header section

 custum header section:

1)继承uiview

2)实现- (id)initWithFrame:(CGRect)frame

       _nameLabel = [[UILabel alloc] init];
        _nameLabel.textAlignment = UITextAlignmentLeft;
        _nameLabel.font = [UIFont boldSystemFontOfSize:14];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.backgroundColor = [UIColor clearColor];

 

       _iconImageView = [[UIImageView alloc]init];

 

       [self addSubview:_nameLabel];

       [self addSubview:_iconImageView];

3)实现 - (void)layoutSubviews

CGRect contentRect = self.bounds;
    if (_iconImageView.image) {
        CGFloat iconOffsetY = floor((contentRect.size.height -  ICON_DIMENSION) / 2);
        _iconImageView.frame = CGRectMake(contentRect.origin.x + PADDING ,iconOffsetY, ICON_DIMENSION, ICON_DIMENSION);
    } else {
        _iconImageView.frame = CGRectZero;
    }
   
    if (_nameLabel.text) {
        CGSize nameTextSize = [_nameLabel.text sizeWithFont:_nameLabel.font];
        CGFloat nameTextOffsetX = _iconImageView.frame.origin.x + _iconImageView.frame.size.width + PADDING;
        _nameLabel.frame = CGRectMake(nameTextOffsetX,0, nameTextSize.width,contentRect.size.height );
    } else {
        _nameLabel.frame = CGRectZero;
    }
 

posted on 2011-02-23 08:49  fairycao  阅读(346)  评论(0)    收藏  举报