IBTTableView.m 3.09 KB
Newer Older
mei's avatar
mei committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
//
//  IBTTableView.m
//  IBTTableViewKit
//
//  Created by Xummer on 15/1/5.
//  Copyright (c) 2015年 Xummer. All rights reserved.
//

#import "IBTTableView.h"
#import "IBTInputViewHandleDelegate.h"

@implementation IBTTableView

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    if (_bHandleKeyboard) {
        if ([self.m_inputHandleDelegate respondsToSelector:@selector(handleInputView:)]) {
            [self.m_inputHandleDelegate handleInputView:self];
        }
        else {
            [self.window endEditing:YES];
        }
    }
}

- (void)setContentInsetTop:(CGFloat)top andBottom:(CGFloat)bottom {
    self.contentInset = UIEdgeInsetsMake(top, 0, bottom, 0);
    self.scrollIndicatorInsets = self.contentInset;
}

@end

@implementation IBTTableView (TableHeaderFooter)

- (IBTUIView *)groupedSectionHeaderWithTitle:(NSString *)title {
    CGRect frame = self.bounds;
    frame.size.height = IBT_GROUP_SECTION_HEIGHT;
    IBTUIView *view = [[IBTUIView alloc] initWithFrame:frame];
    view.backgroundColor = [UIColor clearColor];
    
    frame = CGRectInset(view.bounds, IBT_GROUP_CELL_LEFT_PADDING, 0);
    UILabel *tLabel = [[UILabel alloc] initWithFrame:frame];
    tLabel.textAlignment = NSTextAlignmentLeft;
    tLabel.font = [UIFont systemFontOfSize:16];
    tLabel.textColor = [UIColor colorWithRed:122/255.0f green:122/255.0f blue:123/255.0f alpha:1];
    tLabel.text = title;
    [view addSubview:tLabel];
    
    return view;
}

+ (IBTUIView *)headerWithTitle:(NSString *)title
                       topGap:(CGFloat)fTopGap
               containerWidth:(CGFloat)fWidth
{
    UILabel *tLabel = [[UILabel alloc] init];
    tLabel.textAlignment = NSTextAlignmentCenter;
    tLabel.font = [UIFont systemFontOfSize:16];
    tLabel.textColor = [UIColor colorWithRed:122/255.0f green:122/255.0f blue:123/255.0f alpha:1];
    tLabel.text = title;
    tLabel.numberOfLines = 0;
    
    CGRect rect = CGRectMake(0, 0, fWidth, 0);
    rect.size.height = [UILabel getHeightWithText:title font:tLabel.font andWidth:fWidth] + fTopGap * 2;
    IBTUIView *view = [[IBTUIView alloc] initWithFrame:rect];
    view.backgroundColor = [UIColor clearColor];
    
    rect = CGRectInset(view.bounds, IBT_GROUP_CELL_LEFT_PADDING, fTopGap);
    
    tLabel.frame = rect;
    
    [view addSubview:tLabel];
    
    return view;
}

- (IBTUIView *)buttonViewWithTitle:(NSString *)title
                             color:(UIColor *)color
                            topGap:(CGFloat)topGap
                           pointer:(UIButton * __autoreleasing *)buttonPointer
                            target:(id)target
                            action:(SEL)selector
{
    return [IBTCustomButtom buttonViewWithTitle:title
                                          color:color
                                         topGap:topGap
                                 containerWidth:CGRectGetWidth(self.bounds)
                                        pointer:buttonPointer
                                         target:target
                                         action:selector];
}

@end