UIView設定圓角 邊框和陰影

2021-07-31 09:29:49 字數 910 閱讀 7251

我們經常需要對view進行圓角設定,有些view是通過設定屬性來設定圓角,一般需要用修改view的layer屬性。

1、直接通過已有屬性設定圓角

對於uibutton、uitextfield等,可以通過對已有屬性的設定來顯示圓角。

uibutton * button = [uibutton buttonwithtype:uibuttontyperoundedrect];

uitextfield * textfield = [uitextfield allo]initwithframe:rect];

textfield.borderstyle = uitextfieldborderstyleroundedrect;

2、修改layer來設定圓角

要匯入#import

**如下:

view.layer.maskstobounds = yes;

view.layer.cornerradius = 5.0;

修改layer除了可以設定圓角之外,還可以給view新增邊框和陰影

3、新增border

**如下:

view.layer.bordercolor = [uicolor colorwithred:value green:value blue:value alpha:1].cgcolor;

view.layer.borderwidth = 1.0;

4、新增陰影

**如下:

view.layer.shadowoffset = cgsizemake(1, 1);

view.layer.shadowradius = 5.0;

view.layer.shadowcolor = [uicolor blackcolor].cgcolor;

view.layer.shadowopacity = 0.8;

設定uiview圓角與陰影

calayer layer theview layer layer setmaskstobounds yes layer setcornerradius theradius layer setborderwidth theborderwidth layer setbordercolor thecol...

UIView顯示圓角邊框 並顯示陰影

自定義乙個繼承uiview的控制項 uilabel namelabel uilabel alloc initwithframe cgrectmake 0,0,150,50 namelabel settext 不否認你的情緒化 namelabel settextalignment nstextalig...

設定view的圓角 邊框 陰影

在ios開發中,任何可見檢視都是繼承於uiview的。繼承體系中,大部分uiview的屬性適用於其任何孩子。而uiview的layer屬性可以繪製uiview的各種效果。其實我們看到的view的動畫實際上也是layer在繪製。objc view plain copy cornerview layer...