1.插曲 想让一个label始终在父控件是上属于居中的效果,可以让它和父控件的大小一样大
2. 取两位小数
%.2f
3.可以进行转译%%相当于一个%
4.在一个空间的内部不要使用self.center来确定内部的一个控件的中心,因为这两个参考的父控件不同
5.drawRect方法只会在显示的时候调用一次。在View即将显示出来的时候调用一次,其他的时候不会再调用了。
- (void)setProgress:(CGFloat)progress
{
_progress = progress;
// 重新绘制圆弧
// [self drawRect:self.bounds];
// 重绘,系统会先创建与view相关联的上下文,然后再调用drawRect
[self setNeedsDisplay];
}
// 注意:drawRect不能手动调用,因为图形上下文我们自己创建不了,只能由系统帮我们创建,并且传递给我们
- (void)drawRect:(CGRect)rect {
// Drawing code
// 创建贝瑟尔路径
CGFloat radius = rect.size.width * 0.5;
CGPoint center = CGPointMake(radius, radius);
CGFloat endA = -M_PI_2 + _progress * M_PI * 2;
UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius - 2 startAngle:-M_PI_2 endAngle:endA clockwise:YES];
[path stroke];
}