Objective-C 更改自定义图像视图对象的宽度
我的主视图上有 3 个按钮,名为 btn_easy、btn_medium 和 btn_hard,我想在单击时更改名为 racquet_green 和 racquet_yellow 的两个自定义图像视图对象的宽度。
单击按钮时我必须开始执行该方法的代码是:
-(IBAction)buttonPressed:(id)sender{
UIButton *button = (UIButton*)sender;
if([button.titleLabel.text isEqualToString:@"easy"]){
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
}
}
有人可以帮我弄清楚如何更改这些自定义视图对象的宽度吗?
谢谢
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"]){
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
工作完美,但是等等 - 我还想让桨集中在视图的顶部和底部。我通过在上面发布的行下面添加两行来做到这一点。
我必须用 4 条线而不是 2 条线来完成此操作,因为如果我在设置桨的宽度之前设置 x,y 位置,则 x,y 位置会稍微偏离。因此,我们首先设置宽度、高度,然后设置 x、y 保持宽度和高度,因为我们不想将其设置回 0,0。
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.
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.