evenodd
evenodd

Reputation: 2126

Shrink UIButton

I have a application that runs a timer and performs a action 30 times a second. What I want to do is change the size of a UIButton i have so that every time the timer goes around, it changes the UIButton so that it is a little bit smaller. I have played with a bunch of things I have found online and I still cant figure it out.

Any ideas?

Upvotes: 0

Views: 278

Answers (2)

Eric
Eric

Reputation: 3895

So, to move the comment out - is this generally what you're trying to do?

-(void) calledWhenTimerGoesRound
{
    NSLog(@"calledWhenTimerGoesRound"); 
    [UIView beginAnimations:nil context:@"MyAnimation"]; 

    CGRect tempFrame = myButton.frame; 
    tempFrame.size.width = tempFrame.size.width - 5.0f; 
    tempFrame.size.height = tempFrame.size.height - 5.0f; 
    myButton.frame = tempFrame;

    [UIView commitAnimations];
}

What does your timer code look like? Here's and example of what should work (resize the button smaller every second):

- (void) startMyTimer
{
    NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(calledWhenTimerGoesRound) userInfo:nil repeats:YES];

    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}

Upvotes: 1

James J
James J

Reputation: 6458

Try something like:

CGRect tempFrame = myButton.frame;    
myButton.frame = CGRectInset(tempFrame,5,5);

Upvotes: 0

Related Questions