JLChen
2021-10-08 f8457b624a75bf8e41489b74f66009eee6891b8b
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
//
//  Copyright (c) 2015年 Anson. All rights reserved.
//
 
#import "UITableView+LeChange.h"
#import "NSString+LeChange.h"
#import <objc/runtime.h>
#import <LCBaseModule/DHPubDefine.h>
 
#define SECTION_FONT_SIZE 13
 
@implementation UITableView (LeChange)
 
- (void)lc_hiddenExternLine
{
    UIView *view =[ [UIView alloc]init];
    view.backgroundColor = [UIColor clearColor];
    [self setTableFooterView:view];
    /*
     当tableview的dataSource为空时,也就是没有数据可显示时,该方法无效,只能在numberOfRowsInsection函数,通过判断dataSouce的数据个数,如果为零可以将tableview的separatorStyle设置为UITableViewCellSeparatorStyleNone去掉分割线,然后在大于零时将其设置为
     
     UITableViewCellSeparatorStyleSingleLine
     */
}
 
- (CGFloat)lc_getHeightOfSectionString:(NSString*)content {
    if (content == nil || content.length == 0) {
        return 0;
    }
    return [self lc_getHeightOfSectionString:content margin:15 defaultHeight:35 fontSize:SECTION_FONT_SIZE];
}
 
- (CGFloat)lc_getHeightOfSectionString:(NSString*)content margin:(CGFloat)margin defaultHeight:(CGFloat)defaultHeight fontSize:(CGFloat)fontSize {
    UIFont *font = [UIFont systemFontOfSize:fontSize];
    CGSize size = CGSizeMake((CGFloat)(DH_SCREEN_SIZE_WIDTH - margin * 2), CGFLOAT_MAX);
    CGFloat headerHeight = [content lc_sizeWithFont:font  size:size].height + 15;
    headerHeight = headerHeight < defaultHeight ? defaultHeight : headerHeight;
    return headerHeight;
}
 
- (UIView*)lc_getSectionViewOfString:(NSString*)content {
    UIView *contentView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, DH_SCREEN_SIZE_WIDTH, [self lc_getHeightOfSectionString:content])];
    contentView.backgroundColor = [UIColor clearColor];
    UILabel *contentLabel = UILabel.new;
    contentLabel.frame = CGRectMake(15, 0, contentView.frame.size.width - 30, contentView.frame.size.height);
    contentLabel.font = [UIFont systemFontOfSize:SECTION_FONT_SIZE];
    contentLabel.textColor = [UIColor colorWithWhite:0.5 alpha:1.0];
    contentLabel.text = content;
    contentLabel.numberOfLines = 0;
    contentLabel.textAlignment = NSTextAlignmentJustified;
    [contentView addSubview:contentLabel];
    
    return contentView;
}
 
@end