我正在尝试创建循环进度指示器.不幸的是,drawRect例程仅从setNeedsDisplay调用第一次和最后一次,它不会创建我正在寻找的渐进填充模式.我已经创建了一个UIView子类,我在其中填充背景,然后更新绘制进度,如下所示:
- (void)drawRect:(CGRect)rect
{
// draw background
CGFloat lineWidth = 5.f;
UIBezierPath *processBackgroundPath = [UIBezierPath bezierPath];
processBackgroundPath.lineWidth = lineWidth;
processBackgroundPath.lineCapStyle = kCGLineCapRound;
CGPoint center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.width / 2);
CGFloat radius = (self.bounds.size.width - lineWidth) / 2;
CGFloat startAngle = (2 * (float)M_PI / 2); // 90 degrees
CGFloat endAngle = (2 * (float)M_PI) + startAngle;
[processBackgroundPath addArcWithCenter:center radius:radius startAngle:startAngle endAngle:endAngle clockwise:YES];
[[UIColor grayColor] set];
[processBackgroundPath stroke];
// draw progress
UIBezierPath *processPath = [UIBezierPath bezierPath];
processPath.lineCapStyle = kCGLineCapRound; …Run Code Online (Sandbox Code Playgroud) 在我的项目中,我使用volley来下载一个JSON流,我将其解析并显示在列表视图中.我使用以下方法加载我的数据:
private void loadEventData(int year, final int month) {
// get volley request queue
requestQueue = cpcApplication.getRequestQueue(getActivity());
String url = "****************?year=" + year
+ "&month=" + month;
pd = ProgressDialog.show(getActivity(), "Loading Events", "Retrieving Data from Server");
pd.setCancelable(true);
JsonObjectRequest jr = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i(TAG, response.toString());
// parse the incoming response
parseJson(response, month);
// notify the listview that the data set has changed
adapter.notifyDataSetChanged();
// set the listview at the top …Run Code Online (Sandbox Code Playgroud)