UIView
的陰影設置主要通過UIView
的layer
的相關屬性來設置
陰影的顏色
imgView.layer.shadowColor = [UIColor blackColor].CGColor;
陰影的透明度
imgView.layer.shadowOpacity = 0.8f;
陰影的圓角
imgView.layer.shadowRadius = 4.f;
陰影偏移量
imgView.layer.shadowOffset = CGSizeMake(4,4);
imgView.layer.shadowOffset = CGSizeMake(0,0);
其實從偏移量上可以看出來,即使偏移量為(0,0)時,圍繞view的四周依然能看到一定陰影。
陰影的路徑
除了通過上面的操作,我們還可以設定陰影的路徑
//路徑陰影 UIBezierPath *path = [UIBezierPath bezierPath]; [path moveToPoint:CGPointMake(-5, -5)]; //添加直線 [path addLineToPoint:CGPointMake(paintingWidth /2, -15)]; [path addLineToPoint:CGPointMake(paintingWidth +5, -5)]; [path addLineToPoint:CGPointMake(paintingWidth +15, paintingHeight /2)]; [path addLineToPoint:CGPointMake(paintingWidth +5, paintingHeight +5)]; [path addLineToPoint:CGPointMake(paintingWidth /2, paintingHeight +15)]; [path addLineToPoint:CGPointMake(-5, paintingHeight +5)]; [path addLineToPoint:CGPointMake(-15, paintingHeight /2)]; [path addLineToPoint:CGPointMake(-5, -5)]; //設置陰影路徑 imgView.layer.shadowPath = path.CGPath;
總結
以上就是這篇文章的全部內容,希望能對各位iOS開發者們能有所幫助,如果有疑問大家可以留言交流。