UIView設定部分角為圓角

2022-08-03 02:42:14 字數 754 閱讀 6553

如果需要將uiview的4個角全部都為圓角,做法相當簡單,只需設定其layer的cornerradius屬性即可(專案需要使用quartzcore框架)。而若要指定某幾個角(小於4)為圓角而別的不變時,這種方法就不好用了。

對於這種情況,stackoverflow上提供了幾種解決方案。其中最簡單優雅的方案,就是使用uibezierpath。下面給出一段示例**。

1 uiview *view2 = [[uiview alloc] initwithframe:cgrectmake(120, 10, 80, 80

)];2 view2.backgroundcolor =[uicolor redcolor];

3[self.view addsubview:view2];

45 uibezierpath *maskpath = [uibezierpath bezierpathwithroundedrect:view2.bounds byroundingcorners:uirectcornerbottomleft | uirectcornerbottomright cornerradii:cgsizemake(10, 10

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

7 masklayer.frame =view2.bounds;

8 masklayer.path =maskpath.cgpath;

9 view2.layer.mask = masklayer;

UIView指定角為圓角

給uiview新增指定角為圓角 原view長這樣 新增以下 uibezierpath maskpath uibezierpath bezierpathwithroundedrect animationview.bounds byroundingcorners uirectcornerbottomle...

UIView如何設定部分圓角

給uiview設定四個圓角很簡單 backgroundview.layer cornerradius 12這樣就實現了給背景圖設定4個半徑12的圓角,但是要是只對上半部分或者某乙個角設定圓角效果要怎麼做呢?多數部落格給出的解決方案還是oc版本,這裡貼一下我寫的swift版本解決方案 let mask...

指定UIView的特定角為圓角

純 只需設定其layer的cornerradius屬性即可 專案需要使用quartzcore框架 xib上只需如圖一那樣設定就行了 uiview view uiview alloc initwithframe cgrectmake 120,10,80,80 view.backgroundcolor ...