給UIView設(shè)置圓角時,傳統(tǒng)方式都是設(shè)置layer的masksToBounds與cornerRadius值羞福。殊不知,這種方式會觸發(fā)離屏渲染(offscreen rendering),導(dǎo)致APP的幀率下降养涮,特別是如果在cell上這么用,tableView滑動時特別耗性能眉抬,會有明顯卡頓贯吓。(我也是瞎比比,不過大伙都這么說)
寫了個分類蜀变,通過一句代碼給UIView設(shè)置圓角悄谐。使用方式如下:
[imageV mj_setCornerRadius:25.0f]; // 無邊框
[imageV mj_setCornerRadius:25.0f borderColor:[UIColorredColor] AndBorderWidth:1.0f]; // 含邊框
實現(xiàn)思路:創(chuàng)建兩個CAShapeLayer,路徑通過貝塞爾曲線UIBezierPath繪制UIView的邊緣路徑path库北,一個ShapeLayer設(shè)置為UIView的遮罩爬舰,另一個加在UIView的layer層。
喜歡點(diǎn)個贊吧寒瓦,MJCornerRadius