Does anyone know how to make a UILabel appear letter by letter like you can see in some games or other.
thanks
Set up an NSTimer to set the text property of the UILabel.
-(void) revealTimer:(NSTimer *)inTimer {
if ( ++mIndex < [mFullString length] ) {
mLabel.text = [mFullString substringToIndex:mIndex];
} else {
mLabel.text = mFullString;
[inTimer invalidate];
}
}
start it up with something like this:
-(void) revealString:(NSString *)inString {
mIndex = 0;
mLabel.text = "";
mFullString = [inString retain];
[NSTimer scheduledTimerWithTimeInterval:0.125 target:self selector:#selector(revealTimer:) userInfo:nil repeats:YES];
}
be sure not to leak mFullString as the above does, and store the timer if you may need to invalidate it.
Related
How can I stop my UIWebView from automatically scrolling on the press of a button?
[web_try loadHTMLString:[NSString stringWithFormat:#"<marquee scrollamount='2' direction='up' loop='true' width='278' height='48'> <font size='3' face='HelveticaNeue-Bold' color='#242424'>%#</font></marquee>", option_value] baseURL:final_url];
i think you can use this code to scroll your view and to stop it just works fine for me
-(void)scrollView
{
NSInteger scroll = 1;
NSString* javascript = [NSString stringWithFormat:#"window.scrollBy(0, %d);",scroll];
[self.currentView stringByEvaluatingJavaScriptFromString:javascript];
if(validateTimer)
{
[timer invalidate];
validateTimer = false;
}
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(scrollView) userInfo:nil repeats:YES];
validateTimer = true;
}
-(IBAction)stopScroll
{
[timer invalidate];
validateTimer = false;
hidden.enabled = FALSE;
}
use -
EDIT -
webView.scrollView.scrollEnabled = NO;
webView.scrollView.bounces = NO;
Here, I think you want to stop scrolling the content of web view. Check code. You have used "marquee" tag which is not controllable by objective c code.
I have looked everywhere but I cannot find out how to do so. I need a simple timer that can count up in milliseconds and can be stopped. (XCode 3.1, Objective-C, iPhone OS Development)
Am I just being daft or is "count-up timer" the same as a stopwatch.
If it is, check out this video tutorial
Here is the sample code which i have done one timer with minute, second, and mili seconds.. So, its helpful for you. And also do it release after not use..
-(void)showTime:(NSTimer *)sender
{
miniSeconds++;
if (miniSeconds == 10)
{
miniSeconds = 0;
seconds++;
if (seconds == 60)
{
seconds = 0;
minutes++;
}
}
timeLabel.text = [NSString stringWithFormat:#"%02i:%02i:%02i",minutes,seconds,miniSeconds];
}
-(void)nextLevelTime
{
[labelTimer invalidate];
miniSeconds = 0;
seconds = 0;
minutes = 0;
}
The nextLevel method use for to stop timer and release all thing..
Use it, I have done with this code..
NSTimer should do it:
Class Reference
Timer Programming Topics
#interface ViewController()
{
UILabel *progress;
NSTimer *timer;
int currMinute;
int currSeconds;
int currHours;
}
#end
#implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
progress=[[UILabel alloc] initWithFrame:CGRectMake(80, 15, 100, 50)];
progress.textColor=[UIColor redColor];
[progress setText:#"Time : 00:00:00"];
progress.backgroundColor=[UIColor clearColor];
[self.view addSubview:progress];
currMinute=00;
currSeconds=00;
currHours=00;
// Do any additional setup after loading the view, typically from a nib.
}
-(void)start
{
timer=[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:#selector(timerFired) userInfo:nil repeats:YES];
}
-(void)timerFired
{
currSeconds+=1;
if(currSeconds==60)
{
currSeconds=0;
currMinute+=1;
if(currMinute==60)
{
currMinute=0;
currHours+=1;
}
}
[_progress setText:[NSString stringWithFormat:#"%#%02d%#%02d%#%02d",#"Time : ",currHours,#":",currMinute,#":",currSeconds]];
if(currMinute==2)//stop at 2 minute
{
[timer invalidate];
}
}
I'm looking for the cleanest way to have a countdown timer fire when a user hits the 'take picture' button. Is there any easy way to do this?
One solution I'm thinking of is to just have a label that updates every second, but is there a way to get it working like Photobooth?
Also, at the last second before the photo is about to be taken I'd like for an image to be displayed briefly while the image is being taken. How can I go about this?
Any help would be great, thanks!
- (IBAction)takePicture:(id)sender {
theTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:#selector(updateLabel:) userInfo:nil repeats:NO];
}
- (void)updateLabel:(NSTimer *)timer {
_timeLabel.text = [NSString stringWithFormat:#"%d", time];
time = time - 1;
if (time == 0) {
[theTimer invalidate];
[_timeLabel performSelector:#selector(setText:) withObject:#"Photo taken!" afterDelay:1.0];
//Code for image shown at last second
} else {
theTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(updateLabel:) userInfo:nil repeats:NO];
}
}
Hope this helps ;)
I'm struggling with this. I saw some code where you can do this :
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doActions) userInfo:nil repeats:YES];
}
Then call it in doActions.
Problem is i want to call it while a button is being pressed, and do actions is an IBaction. I keep getting a sigAbrt.
Can someone give me some sample code where you cay change a label from 'on' to 'off' every 1 second while a button is being pressed?
EDIT
i mean if doActions looks like this
- (IBAction) doActions {
for(int j; j<100; j++){
theLabel.hidden != theLabel.hidden;
//Does invalidate timer go here?
}
}
It still isn't clear to me, what you're trying to accomplish: I would have found it much easier, if you simply had it written down in plain english, after all.
That said, here's what I think will get you where you want to go:
// Assuming ivars:
// NSTimer* toggleTimer
// NSUInteger toggleCount
- (void)toggleTimerFired:(NSTimer*)timer
{
if ( toggleCount++ >= 100 ) {
[self stopToggling:self];
return;
}
// do whatever you need to do a hundred times here
}
- (IBAction)stopToggling:(id)sender
{
[toggleTimer invalidate], toggleTimer = nil; // you don't want dangling pointers...
// perform any other needed house-keeping here
}
- (IBAction)startToggling:(id)sender
{
[self stopToggling:self]; // if `startToggling:` will NEVER be called when a timer exists, this line CAN be omitted.
toggleCount = 0;
toggleTimer = [NSTimer scheduledTimerWithTimeInterval:1. target:self selector:#selector(toggleTimerFired:) userInfo:nil repeats:YES];
}
Depending on what exactly you want to do, startToggling: needs to be sent on either touchUpInside or touchDown. In the second case, stopToggling: probably needs to be called on any touchUp... event of the button.
- (void)startTimer {
pauseTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(doActions) userInfo:nil repeats:YES];
}
- (void) doActions {
theLabel.hidden != theLabel.hidden;
}
I want to change my NSTimer code to to use applicationSignificantTimeChange
This is what I have right now.
Basically I want to change the timer, instead of changing every 5 seconds for example I want these textLabels to change at 12am every night anyone help me out?
h file
NSTimer *timer;
IBOutlet UILabel *textLabel;
m file
- (void)onTimer {
static int i = 0;
if ( i == 0 ) {
textLabel.text = #"iphone app";
}
else if ( i == 1 ) {
textLabel.text = #" Great App!";
}
else if ( i == 2 ) {
textLabel.text = #" WOW!";
}
else {
textLabel.text = #" great application again!!";
i = -1;
}
i++;
}
timer =[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:#selector(onTimer) userInfo:nil repeats:YES];
Did you check initWithFireDate:interval:target:selector:userInfo:repeats: method of NSTimer? Click here for more details