3

UIButton を iPhone 画面の右下隅に固定したい。3.5インチと4インチの両方の画面で。

これが私が書いたコードです。ただし、iPhone4 と iPhone5 の両方で、ボタンは常に x=265,y=361 のままです。

UIImage* plusImage = [UIImage imageNamed:@"Plus.png"];
UIButton* plusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[plusButton setImage:plusImage forState:UIControlStateNormal];
[plusButton setFrame:CGRectMake(265, 361, plusImage.size.width, plusImage.size.height)];
plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self.view addSubview:plusButton];

柔軟な上マージンと左マージンを取るように自動サイズ変更マスクを設定しましたが、うまくいきませんでした。私は何を取りこぼしたか?助けてください。

4

3 に答える 3

4
UIImage* plusImage = [UIImage imageNamed:@"Plus.png"];
UIButton* plusButton = [UIButton buttonWithType:UIButtonTypeCustom];
[plusButton setImage:plusImage forState:UIControlStateNormal];
CGSize viewSize = self.view.frame.size;
[plusButton setFrame:CGRectMake(viewSize.width - plusImageSize.width, viewSize.height - plusImageSize.height, plusImage.size.width, plusImage.size.height)];
plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin;
[self.view addSubview:plusButton];

代わりにそれを試してください。

于 2013-01-08T11:03:18.583 に答える
0

試す plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin

于 2013-01-08T10:48:24.240 に答える
0

これらすべてのマスキングを次のように使用しました

plusButton.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin;

それが機能していることを確認してください。

于 2013-01-08T10:55:51.560 に答える