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;
效果有關uibezierpath的知識請看:
uibezierpath介紹
iOS 控制項加陰影
下面以給cell加陰影為例介紹加陰影的方法 self.contentview.backgroundcolor uicolor whitecolor self.contentview.layer.shadowcolor uicolor blackcolor cgcolor 陰影的角度,分別是靠右和靠下...
iOS之控制項新增邊框和陰影
新增顯示 新增邊框 calayer layer imageview layer layer.bordercolor uicolor red color cgcolor layer.borderwidth 5.0f 新增四個邊陰影 imageview.layer.shadowcolor uicolor...
iOS之UI控制項之TableView詳細解釋
建立 uitableview datatable uitableview alloc initwithframe cgrectmake 0,0,320,420 datatable setdelegate self datatable setdatasource self self.view adds...