时,只为layer的backgroundColor和border设置圆角;而不会对layer的contents设置圆角,除非同时设置了layer.masksToBounds为true或者UIView的clipsToBounds cgImage view1.layer.masksToBounds = true view1.clipsToBounds = true view.addSubview cgImage view1.layer.masksToBounds = true view1.clipsToBounds = true view.addSubview 有没有隐约感觉到一点触发规律: 设置了cornerRadius 同时设置了backgroundColor或者borderWidth和content 设置了masksToBounds或者clipsToBounds cornerRadius+clipsToBounds 同时打开backgroundColor|borderWidth,cornerRadius,contents,masksToBounds这个情况前面已经分析过了
; name = tableCellGroupedBackgroundColor>>> | | <UIView: 0x10fe2d310; frame = (0 0; 375 120); clipsToBounds = <CAGradientLayer: 0x280b9dc40>> | | | <UIImageView: 0x10fe70710; frame = (0 16; 28 28); clipsToBounds = <CAGradientLayer: 0x280b9e1c0>> | | | <UIImageView: 0x10ffacfd0; frame = (0 16; 28 28); clipsToBounds = <CAGradientLayer: 0x280b9e540>> | | | <UIImageView: 0x10ffab1f0; frame = (0 16; 28 28); clipsToBounds = <CAGradientLayer: 0x280b9ea20>> | | | <UIImageView: 0x10ffa95d0; frame = (0 16; 28 28); clipsToBounds
backView.layer.borderWidth = 1; backView.layer.borderColor = [UIColor blackColor].CGColor; backView.clipsToBounds :self action:@selector(passwordClick:) forControlEvents:UIControlEventTouchUpInside]; login_btn.clipsToBounds pass_btn.layer.borderWidth = 1; pass_btn.layer.borderColor = [UIColor lightGrayColor].CGColor; pass_btn.clipsToBounds
在这里插入图片描述 I 、 iOS设置视图的cornerRadius属性失效的解决方案 1.1 解决步骤 1、尝试设置_numberLab.clipsToBounds = YES;2、尝试设置 [self.numberLab masksToBounds和clipsToBounds是不同的,前者指子layer层在超出父layer时是否被裁剪(masksToBounds是CALayer的属性),而后者指子view在超出父view 时是否被裁剪(clipsToBounds是UIView的属性)。
I iOS设置视图cornerRadius属性失效的解决方案 1.1 解决步骤 1、尝试设置_numberLab.clipsToBounds = YES;2、尝试设置 [self.numberLab layoutIfNeeded masksToBounds和clipsToBounds是不同的,前者指子layer层在超出父layer时是否被裁剪(masksToBounds是CALayer的属性),而后者指子view在超出父view 时是否被裁剪(clipsToBounds是UIView的属性)。
; name = tableCellGroupedBackgroundColor>>> | | <UIView: 0x10fe2d310; frame = (0 0; 375 120); clipsToBounds = <CAGradientLayer: 0x280b9dc40>> | | | <UIImageView: 0x10fe70710; frame = (0 16; 28 28); clipsToBounds = <CAGradientLayer: 0x280b9e1c0>> | | | <UIImageView: 0x10ffacfd0; frame = (0 16; 28 28); clipsToBounds = <CAGradientLayer: 0x280b9e540>> | | | <UIImageView: 0x10ffab1f0; frame = (0 16; 28 28); clipsToBounds = <CAGradientLayer: 0x280b9ea20>> | | | <UIImageView: 0x10ffa95d0; frame = (0 16; 28 28); clipsToBounds
self.profileImageView.layer.cornerRadius = self.profileImageView.frame.size.width / 2 self.profileImageView.clipsToBounds 其次,你必须将clipsToBounds属性设置为YES,这样layer才能生效。 现在编译和运行应用程序,你会得到一个圆形头像。 ? 非常容易吧。只需两行代码,图像从方形变为圆形。
self.appImageView.layer.cornerRadius = 10; self.appImageView.layer.masksToBounds = YES; // self.appImageView.clipsToBounds
circleBtn.layer.cornerRadius = 5; //第二部:设置剪切 _circleBtn.layer.masksToBounds =YES; //CALayer的setMaskToBounds属性和UIView的clipsToBounds
:@"StarsForeground"]; [self addSubview:self.foregroundImage]; // 切割视图 self.foregroundImage.clipsToBounds
基本UIScrollerView.png 然后设置我们通常会忽略UIScrollerView的一个属性clipsToBounds为NO,默认是Yes,你会看到_scrollerView其它部分相邻的图片 ,但是你会发现那部分相邻的图片不会响应在它上面的任何触摸事件,因为那部分子视图超出了它的父视图,可以用响应链机制解决这个问题: _scrollerView.clipsToBounds = NO; //
imageview in self.progress.subviews) { imageview.layer.cornerRadius = 2; imageview.clipsToBounds
当然图片多了能够使用clipsToBounds剪裁。 (2)但。 imageNamed:@"big2.png"] forBarMetrics:UIBarMetricsDefault]; //假设图片太大会向上扩展侵占状态栏的位置,在状态栏下方显示 //clipsToBounds 就是把多余的图片裁剪掉 self.navigationController.navigationBar.clipsToBounds=YES; //设置导航标题 [self.navigationItem
然后随着拖拽滑动逐渐改变right以及left图片的相对位置X坐标,直至复位,回到它们在WSLAnimationView上的初始位置X=0,超出父视图的部分裁剪掉,也是设置WSLAnimationView对象的clipsToBounds instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { self.clipsToBounds
imageView.layer.rasterizationScale = [UIScreen mainScreen].scale; imageView.layer.shouldRasterize = YES; imageView.clipsToBounds
然后随着拖拽滑动逐渐改变right以及left图片的相对位置X坐标,直至复位,回到它们在WSLAnimationView上的初始位置X=0,超出父视图的部分裁剪掉,也是设置WSLAnimationView对象的clipsToBounds instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { self.clipsToBounds
<UICollectionView: 0x7fc565076000; frame = (0 0; 375 197); clipsToBounds = YES; gestureRecognizers
init]; self.imageView1.contentMode = UIViewContentModeScaleAspectFill; self.imageView1.clipsToBounds init]; self.imageView2.contentMode = UIViewContentModeScaleAspectFill; self.imageView2.clipsToBounds
, width: 100, height: 50) visualEffectView.layer.cornerRadius = 20 visualEffectView.clipsToBounds
alloc] initWithFrame: frame]; self.displayLabel.layer.cornerRadius = 5; self.displayLabel.clipsToBounds