源碼位址:點選打開連結
一,圖檔裁剪。
使用Graphics Context圖形上下文進行圖檔裁剪操作,結合UIBezierPath畫出路徑,然後在CGContextRef中按照路徑裁剪。
(1),在Rect中畫出對應的形狀路徑。
//繪制珠寶形路徑
+(UIBezierPath *)jewelryPathWithInRect:(CGRect)rect;
//繪制三角形路徑
+(UIBezierPath *)trianglePathWithInRect:(CGRect)rect;
//繪制五角星路徑
+(UIBezierPath *)fivePointStarPathWithInRect:(CGRect)rect;
//繪制橢圓鋸齒形路徑
+(UIBezierPath*)sawtoothPathWithInRect:(CGRect)rect;
//繪制心形路徑
+(UIBezierPath *)heartPathWithInRect:(CGRect)rect;
(2),根據路徑裁剪圖檔。
-(UIImage*)clipWithPath:(UIBezierPath*)path InRect:(CGRect)rect;
效果:
二,圖檔添加相框。
圖檔添加關鍵在與兩張圖檔的疊加,使用Graphics Context圖形進行圖檔疊加,把相框圖檔蓋在原有圖檔之上,合成一樁圖檔。
(1),把原圖檔按相框大小做合适的矩形裁剪。
-(UIImage*)frameSquareClipInRect:(CGRect)rect;
(2),把原圖和相框疊加成新圖檔。
-(UIImage*)frameAddImage:(UIImage*)topImage;
效果: