操作按钮常常需要设置视图圆角,比如注册页面的注册按钮。
1、尝试设置_numberLab.clipsToBounds = YES;
2、尝试设置 [self.numberLab layoutIfNeeded];
之后再执行cornerRadius
在设置完约束后, 并不能马上得到它的frame, 只要添加[self.view layoutIfNeeded]; 就能拿到frame设置圆角了
- (void)layoutSubviews{
[super layoutSubviews];
[self.numberLab layoutIfNeeded];
[self.contentView bringSubviewToFront:self.numberLab];
self.numberLab.layer.cornerRadius =self.numberLab.height*0.5;
}
3、尝试设置_numberLab.layer.masksToBounds = YES;
用法
- (void)layoutSubviews {
[super layoutSubviews];
[self.titleV layoutIfNeeded];
[self.titleV setCornerOnTop:kAdjustRatio(20)];
}
setCornerOnTop:
方法的实现
#pragma mark - Corner Radius
- (void)setCornerOnTop:(CGFloat)radius {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerTopRight)
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnBottom:(CGFloat)radius {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerBottomLeft | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnLeft:(CGFloat)radius {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopLeft | UIRectCornerBottomLeft)
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnRight:(CGFloat)radius {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:(UIRectCornerTopRight | UIRectCornerBottomRight)
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnTopLeft:(CGFloat)radius {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerTopLeft
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnTopRight:(CGFloat)radius {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerTopRight
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnBottomLeft:(CGFloat)radius {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerBottomLeft
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerOnBottomRight:(CGFloat)radius {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
byRoundingCorners:UIRectCornerBottomRight
cornerRadii:CGSizeMake(radius, radius)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setAllCorner:(CGFloat)radius {
UIBezierPath *maskPath;
maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds
cornerRadius:radius];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.bounds;
maskLayer.path = maskPath.CGPath;
self.layer.mask = maskLayer;
}
- (void)setCornerRadius:(CGFloat)radius {
[self.layer setCornerRadius:radius];
[self.layer setMasksToBounds:YES];
}
iOS去掉TabBar的顶部黑线,并添加发光的阴影
https://blog.csdn.net/z929118967/article/details/93181646
表格视图(UITableView)主要用来罗列展示数据项如果数据量很大,那么表格中将需要同样多的cell视图来显示,而cell的大量创建和初始化会造成内存压力,影响界面的流畅性,因此对表格视图的加载优化十分重要。UITableView的·滚动优化·主要在于以下两个方面:
例如,在异步请求服务器数据时,提前将cell高度计算好并作为datasource的一个数据存到数据库供随时取用。