tableView 背景

//
//  JZLBaseTableView.h
//  JZLIntegrationDemo
//
//  Created by 微指 on 15/3/16.
//  Copyright (c) 2015年 JZL. All rights reserved.
//

/*

#import <UIKit/UIKit.h>

#import "JZLBackgroundView.h"

@interface JZLBaseTableView : UITableView

- (void)addJZLBackgroundViewWithStyle:(JZLBackgroundViewStyle)style
                                image:(UIImage *)image
                                 text:(NSString *)text
                             delegate:(id<JZLBackgroundViewDelegate>)delegate;

- (void)removeJZLBackgroundView;

@end

 */

//
//  JZLBaseTableView.m
//  JZLIntegrationDemo
//
//  Created by 微指 on 15/3/16.
//  Copyright (c) 2015年 JZL. All rights reserved.
//

/*

#import "JZLBaseTableView.h"



@interface JZLBaseTableView ()

{
    JZLBackgroundView *_jzlBackgroundView;
}

@end

@implementation JZLBaseTableView

- (void)dealloc
{
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
    }
    return self;
}

#pragma mark - 添加背景
/// 添加背景
- (void)addJZLBackgroundViewWithStyle:(JZLBackgroundViewStyle)style image:(UIImage *)image text:(NSString *)text delegate:(id)delegate
{
    [self removeJJBackgroundView]; // 先移除一遍,在创建
    
    if (_jzlBackgroundView == nil)
    {
        _jzlBackgroundView = [[JZLBackgroundView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.width, self.height)
                                                              style:style
                                                              image:image
                                                               text:text];
        _jzlBackgroundView.delegate = delegate;
        [self addSubview:_jzlBackgroundView];
        [_jzlBackgroundView release];
    }
}
/// 移除背景
- (void)removeJZLBackgroundView
{
    if (_jzlBackgroundView && [_jzlBackgroundView superview]) {
        [_jzlBackgroundView removeFromSuperview];
        _jzlBackgroundView = nil;
    }
}



@end
 
  */

//
//  JZLBackgroundView.h
//  JZLIntegrationDemo
//
//  Created by 微指 on 15/3/16.
//  Copyright (c) 2015年 JZL. All rights reserved.
//


/*

#import <UIKit/UIKit.h>

typedef NS_ENUM(NSInteger, JZLBackgroundViewStyle) {
    
    JZLBackgroundViewStyleDefault = 0,
    
    JZLBackgroundViewStyleNearby
    
};

// 可添加代理处理需要的操作

@interface JZLBackgroundView : UIView

- (id)initWithFrame:(CGRect)frame
              style:(JZLBackgroundViewStyle) style
              image:(UIImage *)image
               text:(NSString *)text;

@end

*/

//
//  JZLBackgroundView.m
//  JZLIntegrationDemo
//
//  Created by 微指 on 15/3/16.
//  Copyright (c) 2015年 JZL. All rights reserved.
//

/*

#import "JZLBackgroundView.h"

#define k_Lbabel_Height 50.0

@implementation JZLBackgroundView

- (id)initWithFrame:(CGRect)frame style:(JZLBackgroundViewStyle)style image:(UIImage *)image text:(NSString *)text
{
    self = [super initWithFrame:frame];
    if (self) {
        
        if (style == JZLBackgroundViewStyleDefault) {
            
            [self makeDefaultWithImage:image text:text];
        } else if (style == JZLBackgroundViewStyleNearby) {
            
            [self makeNearbyWithImage:image text:text];
        }
        
    }
    
    return self;
}

- (void)makeDefaultWithImage:(UIImage *)image text:(NSString *)text
{
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(0.0, self.height/2.0-image.size.height, SCREEN_WIDTH, image.size.height);
    imageView.userInteractionEnabled = YES;
    imageView.contentMode = UIViewContentModeCenter;
    imageView.backgroundColor = [UIColor clearColor];
    [self addSubview:imageView];
    
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(0.0, imageView.bottom, SCREEN_WIDTH, k_Label_Height);
    label.userInteractionEnabled = YES;
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = 1;
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:14.0];
    label.text = text;
    label.numberOfLines = 2;
    [self addSubview:label];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refreshData:)];
    [self addGestureRecognizer:tap];
    
    
}

- (void)makeNearbyWithImage:(UIImage *)image text:(NSString *)text
{
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(0.0, self.height/2.0-image.size.height, SCREEN_WIDTH, image.size.height);
    imageView.contentMode = UIViewContentModeCenter;
    imageView.backgroundColor = [UIColor clearColor];
    [self addSubview:imageView];
    
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(0.0, imageView.bottom, SCREEN_WIDTH, k_Label_Height);
    label.backgroundColor = [UIColor clearColor];
    label.textAlignment = 1;
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:14.0];
    label.text = text;
    label.numberOfLines = 2;
    [self addSubview:label];
    
    NSArray *titles = @[@"1500米", @"2000米", @"3000米"];
    for (int i = 0; i < 3; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(20.0+(80.0+20.0)*i, label.bottom, 80.0, 40.0);
        btn.layer.masksToBounds = YES;
        btn.layer.cornerRadius = 5.0;
        btn.layer.borderWidth = 0.5;
        btn.layer.borderColor = [[UIColor grayColor] CGColor];
        [btn setTitle:[titles objectAtIndex:i] forState:UIControlStateNormal];
        [btn setTitleColor:k_COMMON_COLOR forState:UIControlStateNormal];
        btn.titleLabel.font = [UIFont systemFontOfSize:15.0];
        if (i == 0) { // 1500米
            btn.tag = 1500;
        } else if (i == 1) { // 2000米
            btn.tag = 2000;
        } else if (i == 2) { // 3000米
            btn.tag = 3000;
        }
        [self addSubview:btn];
        [btn addTarget:self action:@selector(clickDistanceBtn:) forControlEvents:UIControlEventTouchUpInside];
    }

}

- (void)refreshData:(UITapGestureRecognizer *)tap
{
    //    NSLog(@"refreshData");
    if ([self.delegate respondsToSelector:@selector(JJBackgroundViewServerResponseAgain)]) {
        [self.delegate JJBackgroundViewServerResponseAgain];
    }
}
/// 点击距离按钮
- (void)clickDistanceBtn:(UIButton *)btn
{
    //    NSLog(@"btn.tag = %d米",(int)btn.tag);
    if ([self.delegate respondsToSelector:@selector(JJBackgroundViewRequestDataAgainWithMeter:)]) {
        [self.delegate JJBackgroundViewRequestDataAgainWithMeter:[NSString stringWithFormat:@"%ld",(long)btn.tag]];
    }
}



@end
 
  */

原文地址:https://www.cnblogs.com/jzlblog/p/4342498.html