Button 設定半圓角和陰影

2021-07-26 16:05:45 字數 880 閱讀 9113

設定半圓角和陰影方法:byroundingcorners:[ 要設定半圓角的方位],下方例子是左上角,右上角

let maskpath =uibezierpath.init(roundedrect: chagebtn.bounds, byroundingcorners:[uirectcorner.topleft ,uirectcorner.topright],cornerradii:cgsize.init(width:5, height:5))

letmasklayer =

cashapelayer

()masklayer.

path

= maskpath.

cgpath

button.layer.mask = masklayer    // 設定button邊角

給檢視設定陰影

view.

shadowcolor

= [[uicolorblackcolor] cgcolor];    // 陰影顏色

view

.layer

.shadowopacity

= 0.5

;     // 不透明度

view

.layer.shadowoffset=

cgsizemake

(0.0f,0.0f);      

注意:

設定圓角後又設定陰影是無效果的,可以嘗試在檢視上再新增一層layer,在新新增的layer上設定陰影效果

新增陰影和設定圓角

圓角 calayer layer theview layer layer setmaskstobounds yes layer setcornerradius theradius layer setborderwidth theborderwidth layer setbordercolor the...

UIView設定圓角 邊框和陰影

我們經常需要對view進行圓角設定,有些view是通過設定屬性來設定圓角,一般需要用修改view的layer屬性。1 直接通過已有屬性設定圓角 對於uibutton uitextfield等,可以通過對已有屬性的設定來顯示圓角。uibutton button uibutton buttonwitht...

iOS 給Button設定圓角

button 的型別 typedef ns enum nsinteger,uibuttontype 六種定義button型別 uibuttontypecustom 0,無型別 uibuttontyperoundedrect,四個角是圓弧 型的 uibuttontypedetaildisclosure...