指定UIView的特定角為圓角

2021-09-11 12:45:46 字數 985 閱讀 8339

純**只需設定其layer的cornerradius屬性即可(專案需要使用quartzcore框架)

xib上只需如圖一那樣設定就行了

uiview *view = [[uiview alloc] initwithframe:cgrectmake(120, 10, 80, 80)];

view.backgroundcolor = [uicolor redcolor];

[self.view addsubview:view2];

uibezierpath *maskpath = [uibezierpath bezierpathwithroundedrect:view2.bounds

byroundingcorners:uirectcornerbottomleft | uirectcornerbottomright

cornerradii:cgsizemake(10, 10)];

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

masklayer.frame         = view.bounds;

masklayer.path          = maskpath.cgpath;

view.layer.mask         = masklayer;

複製**

其中byroundingcorners:uirectcornerbottomleft | uirectcornerbottomright指定了需要成為圓角的角。該引數是uirectcorner型別的,可選的值有:

從名字很容易看出來代表的意思,使用「|」來組合就好了。

微博: @danny_呂昌輝

部落格: superdanny

2015 年 08月 20日

UIView指定角為圓角

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

iOS 指定UIView的某幾個角為圓角

如果需要將uiview的4個角全部都為圓角,做法相當簡單,只需設定其layer的cornerradius屬性即可 專案需要使用quartzcore框架 而若要指定某幾個角 小於4 為圓角而別的不變時,這種方法就不好用了。對於這種情況,stackoverflow上提供了幾種解決方案。其中最簡單優雅的方...

iOS 指定UIView的某幾個角為圓角

如果需要將uiview的4個角全部都為圓角,做法相當簡單,只需設定其layer的cornerradius屬性即可 專案需要使用quartzcore框架 而若要指定某幾個角 小於4 為圓角而別的不變時,這種方法就不好用了。對於這種情況,stackoverflow上提供了幾種解決方案。其中最簡單優雅的方...