开发者

objective-c change width of custom image view object

I have 3 buttons on my main view named btn_easy, btn_medium, and btn_hard that I would like to make change the width of two custom image view objects named racquet_green, and racquet_yellow upon clicking.

The code I have to start the executing of the method upon button click is:

   -(IBAction)buttonPressed:(id)sender{
      UIButton *button = (UIButton*)sender;
    if([button.titleLabel.text isEqualToString:@"easy"]){
 开发者_Python百科       NSLog(@"easy clicked");
            //change width of racquet_green and racquet_yellow to 100px
      }
      if([button.titleLabel.text isEqualToString:@"medium"]){
        NSLog(@"medium clicked");
            //change width of racquet_green and racquet_yellow to 60px
      }
      if([button.titleLabel.text isEqualToString:@"hard"]){
        NSLog(@"hard clicked");
           //change width of racquet_green and racquet_yellow to 40px
      }
   }

can someone please help me figure out how to change the width of these custom view objects?

thanks


rect = CGRectMake(0, 0, PixelsX, PixelsY);
[myView setFrame:rect];


   [racquet_yellow setFrame:CGRectMake(0,0,35,5)];
   [racquet_green setFrame:CGRectMake(0,0,35,5)];

works perfectly but wait - I also want to make the paddles centered on the top and bottom of the view. I did that by adding 2 lines below the lines posted above.

[racquet_yellow setFrame:CGRectMake(((self.view.bounds.size.width/2)-(racquet_yellow.bounds.size.width/2)),self.view.bounds.size.height-20,50,5)];
[racquet_green setFrame:CGRectMake(((self.view.bounds.size.width/2)-(racquet_green.bounds.size.width/2)),15,50,5)]; 

I have to do this with 4 lines rather than 2 because if I set the x,y position before I set the width of the paddles then the x,y position is slightly off. So, we set the width,height first then the x,y keeping width and height because we don't want to set it back to 0,0.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜