첨부 된 그림과 같이 타이머를 사용하여 UIButton을 만들고 싶습니다. 어떻게해야합니까? MBProgressHUD를 UIButton에 추가하면 도움이 될까요? 내가 어떻게 타이머를 나타내는 원을 그리하는 방법을 보여줄 수타이머가있는 UIButton
waze http://www.efytimes.com/admin/useradmin/rte/my_documents/my_pictures/CA6_Waze3.PNG
첨부 된 그림과 같이 타이머를 사용하여 UIButton을 만들고 싶습니다. 어떻게해야합니까? MBProgressHUD를 UIButton에 추가하면 도움이 될까요? 내가 어떻게 타이머를 나타내는 원을 그리하는 방법을 보여줄 수타이머가있는 UIButton
waze http://www.efytimes.com/admin/useradmin/rte/my_documents/my_pictures/CA6_Waze3.PNG
, 난 당신이 거기에서 걸릴 수 있습니다 확신합니다.
TimerButton.h
#import <UIKit/UIKit.h>
@interface TimerButton : UIView
{
float currentAngle;
float currentTime;
float timerLimit;
NSTimer *timer;
}
@property float currentAngle;
-(void)stopTimer;
-(void)startTimerWithTimeLimit:(int)tl;
@end
TimerButton.m
#import "TimerButton.h"
@implementation TimerButton
#define DEGREES_TO_RADIANS(degrees) ((3.14159265359 * degrees)/ 180)
#define TIMER_STEP .01
@synthesize currentAngle;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
self.backgroundColor = [UIColor clearColor];
currentAngle = 0;
}
return self;
}
- (void)drawRect:(CGRect)rect
{
UIBezierPath* aPath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(50, 50)
radius:45
startAngle:DEGREES_TO_RADIANS(0)
endAngle:DEGREES_TO_RADIANS(currentAngle)
clockwise:YES];
[[UIColor redColor] setStroke];
aPath.lineWidth = 5;
[aPath stroke];
}
-(void)startTimerWithTimeLimit:(int)tl
{
timerLimit = tl;
timer = [NSTimer scheduledTimerWithTimeInterval:TIMER_STEP target:self selector:@selector(updateTimerButton:) userInfo:nil repeats:YES];
}
-(void)stopTimer
{
[timer invalidate];
}
-(void)updateTimerButton:(NSTimer *)timer
{
currentTime += TIMER_STEP;
currentAngle = (currentTime/timerLimit) * 360;
if(currentAngle >= 360) [self stopTimer];
[self setNeedsDisplay];
}
@end
이 시도 것을주고 당신은 더 설명이 필요하면 알려주세요 : 여기에 코드입니다.
이 일을 .. 고마워! – ddd
타이머 표시기가 그림과 같이 회전하는 원이되어야합니까? NSTimer와 함께 UIProgressView를 사용하면 1 초마다 진행 상황을 업데이트 할 수 있습니다. –
시도해 보셨습니까? – NSPunk