iOS 設定圓角

2021-09-30 14:42:03 字數 1647 閱讀 2194

uiimage * image = [uiimage imagenamed:@"1"];

//方式一: 設定layer屬性

uiimageview *imageview1 = [[uiimageview alloc ] initwithframe:cgrectmake(100, 100, 100, 100)];

[imageview1 setimage:image];

//設定圓角大小

imageview1.layer

.cornerradius = 20

; //maskstobounds 預設是no,需要設定成yes,將檢視的圖層上的子圖層超出部分擷取掉。

imageview1.layer

.maskstobounds = yes;

[self.view addsubview:imageview1];

//方法二:使用貝塞爾曲線uibezierpath和core graphics框架畫出乙個圓角

uiimageview *imageview2 = [[uiimageview alloc] initwithframe:cgrectmake(100, 220, 100, 100)];

[imageview2 setimage:image];

uigraphicsbeginimagecontextwithoptions(imageview2.bounds

.size, no, [uiscreen mainscreen].scale);

[[uibezierpath bezierpathwithroundedrect:imageview2.bounds cornerradius:20] addclip];

[imageview2 drawrect:imageview2.bounds];

imageview2.image = uigraphicsgetimagefromcurrentimagecontext();

uigraphicsendimagecontext();

[self.view addsubview:imageview2];

//方法三:使用cashapelayer和uibezierpath設定圓角

uiimageview *imageview3 = [[uiimageview alloc] initwithframe:cgrectmake(100, 330, 100, 100)];

[imageview3 setimage:image];

uibezierpath *maskpath = [uibezierpath bezierpathwithroundedrect:imageview3.bounds byroundingcorners:uirectcornerallcorners cornerradii:cgsizemake(20,20)];

cashapelayer *masklayer = [[cashapelayer alloc] init];

masklayer.frame = imageview3.bounds

; masklayer.path = maskpath.cgpath

; imageview3.layer

.mask = masklayer;

[self.view addsubview:imageview3];

IOS 圓角設定

ios 系統自帶的 view 元件都是正方形的,看起來都太生硬,有時候我需要變成圓角形式,如下圖 具體的實現是使用quartzcore庫,下面我具體的描述一下實現過程 實現 標頭檔案 import import inte ce ipad webwiewviewcontroller uiviewcon...

iOS 給Button設定圓角

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

iOS 設定控制項的部分圓角

目標 給控制項新增部分圓角或半邊圓角 方案 用貝塞爾曲線與cashapelayer結合使用,將控制項的layer層的mask設定為前面操作過的cashapelayer 給控制項新增部分圓角 param rect 控制項的rect param corners 需要設定為圓角的角 uirectcorne...