开发者

Issue with CGRectMake for Button Size

开发者 https://www.devze.com 2023-04-12 02:02 出处:网络
I am having an issue with resizing my button with CGRectMake. As you can see below, it should be working, but it doesn\'t change at all.

I am having an issue with resizing my button with CGRectMake. As you can see below, it should be working, but it doesn't change at all.

GameTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
GameTwo.titleLabel.font = [UIFont systemFontOfSize:22];
GameTwo.titleLabel.lineBreakMode = UILineBreakModeHeadTruncation;
[GameTwo setTitle:(@"Game Two") forState:UIControlStateNormal];
GameTwo.frame = CGRectMake(10, 10, 100, 50);
[GameTwo addTarget:self action:@selector(gameTwo) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:GameTwo];

I guess i开发者_如何学Go have two questions as well. How does one change button size depending on portrait mode and then for landscape mode.


A good rule of thumb for "It should be working, but it doesn't change at all" bugs is to search for the bug elsewhere.

Did you check the GameTwo class implementation (and superclasses) thoroughly? Did you set an autoresizing mask? Do you somewhere set the frame on a bounds change notification?


GameTwo = [UIButton buttonWithType:UIButtonTypeRoundedRect];
GameTwo.titleLabel.font = [UIFont systemFontOfSize:22];
GameTwo.titleLabel.lineBreakMode = UILineBreakModeHeadTruncation;
[GameTwo setTitle:(@"Game Two") forState:UIControlStateNormal];
GameTwo.frame = CGRectMake(10, 10, 100, 50); [GameTwo addTarget:self
action:@selector(gameTwo)
forControlEvents:UIControlEventTouchUpInside]; [self.view
addSubview:GameTwo];

Works perfect. (This is what was in the original question) The issue was I was trying to use another function to place were the button should go. I didn't understand that the first two variables in this case (10, 10...) were the placement of the button. Now i do. Cheers.

0

精彩评论

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