UIBezierPath繪製進度條

2021-07-28 00:06:57 字數 1260 閱讀 4622

#import "progressbtn.h"

/* 寫乙個巨集 mymin(a,b) 返回最小值

寫乙個巨集 mymin3(a,b,c) 返回最小值

*/#define mymin(a,b) (((a) < (b))?(a):(b))

#define mymin3(a,b,c) mymin(mymin(a,b),c)

@implementation hkprogressbtn

-(void)setprogress:(float)progress

{ _progress = progress;

//設定標題

[self settitle:[nsstring stringwithformat:@"%.02f%%",_progress * 100] forstate:(uicontrolstatenormal)];

//重新整理檢視

[self setneedsdisplay];

// 自己定義

-(void)drawrect:(cgrect)rect

{

cgsize s = rect.size;

cgpoint center = cgpointmake(s.width * 0.5, s.height * 0.5);

cgfloat r = mymin(s.height,s.width) * 0.5;

r -= 5.0;

cgfloat startang = - m_pi_2;

cgfloat endang = self.progress * 2 * m_pi + startang;

/** 1.圓心

2.半徑

3.起始角度

4.結束角度

5.順時針

*/uibezierpath * path = [uibezierpath bezierpathwitharccenter:center radius:r startangle:startang endangle:endang clockwise:yes];

//設定線條寬度

path.linewidth = 10.0;

path.linecapstyle = kcglinecapround;

//設定顏色

[[uicolor bluecolor] setstroke];

//繪製路徑

[path stroke];

@end

UIBezierPath畫圓弧的記錄

uibezierpath通過 void addarcwithcenter cgpoint center radius cgfloat radius startangle cgfloat startangle endangle cgfloat endangle clockwise bool clock...

UIBezierPath 畫圓弧(角度問題)

uibezierpath通過 void addarcwithcenter cgpoint center radius cgfloat radius startangle cgfloat startangle endangle cgfloat endangle clockwise bool clock...

UIBezierPath畫圓弧的記錄

文中的圖很重要!根據下文,完成了下圖的mask 如下 cgsize size self.size 畫路徑 uibezierpath maskpath uibezierpath bezierpath bottom line maskpath movetopoint cgpointmake size.w...