我想要一個黑色的背景俯树,mj_refresh 背景黑色
第0種方法:設(shè)置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; // 設(shè)置某一個角(自動布局可用)
self.backView.clipsToBounds = YES; // 設(shè)置這個屬性勇蝙,子視圖超出邊界裁剪掉
self.backView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.backView];
其中:設(shè)置四個角
typedef NS_OPTIONS (NSUInteger, CACornerMask)
{
kCALayerMinXMinYCorner = 1U << 0, // 左上角
kCALayerMaxXMinYCorner = 1U << 1, // 右上角
kCALayerMinXMaxYCorner = 1U << 2, // 左下角
kCALayerMaxXMaxYCorner = 1U << 3, // 右下角
};
第一種方法:
一耽梅、
1除盏、原理:設(shè)置一個黑色的UIview
在mj_refresh(mj_refresh也是insertSubview在tableview上的)之后insertSubview:
添加到tableview上叉橱,在設(shè)置headerView的圓角。
2痴颊、改變y偏移量contentOffset.y
- (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];
// 設(shè)置刷新背景:
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;
// 設(shè)置圓角:
_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;
// 圓環(huán)的顏色
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 {
// 設(shè)置刷新背景:
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;
}