ios ~ UITableView 设置上边两个圆角,下拉的时候保持MJ_refresh 小圆圈在上边显示

我想要一个黑色的背景,mj_refresh 背景黑色

第0种方法:设置UIView的

view.layer.maskedCorners
代码:

    _backView = [[UIView alloc] initWithFrame:CGRectMake(0, k_Height_StatusBar + k_Height_NavContentBar, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - k_Height_StatusBar - k_Height_NavContentBar)];
    self.backView.layer.masksToBounds = YES;
    self.backView.layer.cornerRadius  = [UIScreen mainScreen].bounds.size.width/375*20;
    self.backView.layer.maskedCorners = kCALayerMinXMinYCorner | kCALayerMaxXMinYCorner; // 设置某一个角(自动布局可用)
    self.backView.clipsToBounds = YES; // 设置这个属性,子视图超出边界裁剪掉
    self.backView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.backView];

其中:设置四个角

typedef NS_OPTIONS (NSUInteger, CACornerMask)
{
  kCALayerMinXMinYCorner = 1U << 0,    // 左上角
  kCALayerMaxXMinYCorner = 1U << 1,   // 右上角
  kCALayerMinXMaxYCorner = 1U << 2,   // 左下角
  kCALayerMaxXMaxYCorner = 1U << 3,  // 右下角
};

第一种方法:

一、

1、原理:设置一个黑色的UIview在mj_refresh(mj_refresh也是insertSubview在tableview上的)之后insertSubview:添加到tableview上,在设置headerView的圆角。
2、改变y偏移量contentOffset.y

IMG_7078.PNG

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.titleLabel.text = @"比赛详情";
    self.view.backgroundColor = ColorGlobalBalck;
    [self setupUI];
    
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self gainMatchDetailRequest];
    }];
    
    [self.tableView.mj_header beginRefreshing];
    
    // 设置刷新背景:
    UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 0)];
    backgroundView.backgroundColor = ColorGlobalBalck;
    [self.tableView insertSubview:backgroundView atIndex:0];
    self.backgroundView = backgroundView;
    
}

二、(切圆角方法 1.)
- (void)setupUI {
    
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, k_Height_StatusBar + k_Height_NavContentBar, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - k_Height_StatusBar - k_Height_NavContentBar) style:UITableViewStyleGrouped];
//    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.backgroundColor = ColorGlobalBalck;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.tableDetailHeaderView;
    
    
    // 设置圆角:
    _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.height)];
    _backView.backgroundColor = ColorGlobalBalck;
//    [self.view addSubview:self.backView];
//    [self.tableView addSubview:self.backView];
    self.tableView.backgroundView = self.backView;
    
    
    UIBezierPath *bezierPath = [UIBezierPath
                                bezierPathWithRoundedRect:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - k_Height_StatusBar - k_Height_NavContentBar)
                                byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                cornerRadii:CGSizeMake([UIScreen mainScreen].bounds.size.width/375*20, [UIScreen mainScreen].bounds.size.width/375*20)];

    CAShapeLayer *layer = [[CAShapeLayer alloc] init];
    layer.lineWidth = [UIScreen mainScreen].bounds.size.width/375*0.1;
    // 圆环的颜色
    layer.strokeColor = RGBA(248, 249, 250, 1).CGColor;
    // 背景填充色
    layer.fillColor = RGBA(248, 249, 250, 1).CGColor;
    layer.path = [bezierPath CGPath];
    [self.backView.layer addSublayer:layer];
    
}
三、改变y偏移量
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // 设置刷新背景:
    CGRect frame = self.backgroundView.frame;
    frame.origin.y = scrollView.contentOffset.y;
    frame.size.height = -scrollView.contentOffset.y;
    self.backgroundView.frame = frame;
}

第二种方法:(切圆角方法 2.)

原理:在tableHeaderView的一个UIView,在这个headerView上添加一个backView,直接正常切backView的圆角: self.layer.masksToBounds = YES;
#import "GWTeamInfoCompetitionHeaderView.h"

@interface GWTeamInfoCompetitionHeaderView ()
@property (nonatomic, strong) UIView *backView;
@end

@implementation GWTeamInfoCompetitionHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = ColorGlobalBalck;
        self.layer.masksToBounds = YES;

        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    _backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, [UIScreen mainScreen].bounds.size.width/375*40)];
    self.backView.backgroundColor = RGBA(248, 249, 250, 1);
    self.backView.layer.masksToBounds = YES;
    self.backView.layer.cornerRadius = [UIScreen mainScreen].bounds.size.width/375*40/2;
    [self addSubview:self.backView];
    
}


@end

使用:

// self.tableView.tableHeaderView = self.myTableHeaderView;

- (GWTeamInfoCompetitionHeaderView *)myTableHeaderView {
    if (!_myTableHeaderView) {
        _myTableHeaderView = [[GWTeamInfoCompetitionHeaderView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width/375*20)];
    }
    return _myTableHeaderView;
}


你可能感兴趣的:(ios ~ UITableView 设置上边两个圆角,下拉的时候保持MJ_refresh 小圆圈在上边显示)