0

StoryBoardはiPhone4の解像度用に構成されており、iPhone 5で実行する場合、UIViewを大きくしたいと思います(高さと幅の両方)。

現在の問題は、ビューが高くなるだけで、広くならないことです。これを実現するには、自動サイズ変更の構成はどうすればよいですか?

ここに画像の説明を入力 ここに画像の説明を入力

4

2 に答える 2

1

画面の高さを参照し、いくつかのパディング値を使用してビュー フレームを設定します。以下は、と呼ばれる UIView のフレームを設定するコードですyourShapeView

// Get the frame of the screen
CGRect screenFrame = [[UIScreen mainScreen] bounds];

// Set padding from the top and bottom of the shape
CGFloat verticalPadding = 40.0f;
CGFloat horizontalPadding = 20.0f;

// Get the height/width values
CGFloat height = screenFrame.size.height - (verticalPadding * 2);
CGFloat width = screenFrame.size.width - (horizontalPadding * 2);

// Set the size of your shape based on the height and padding
yourShapeView.frame = CGRectMake(horizontalPadding, verticalPadding, width, height);
于 2013-07-13T01:44:50.367 に答える
1

フレームの変更をキャッチするには、オーバーライドされUIViewたメソッドで のサブクラスを使用する必要があるでしょう。setFrame:

- (void)setFrame:(CGRect)frame
{
    frame.size.width = frame.size.height; // Make the *width* always equal to the *height*. Logic could go here, etc.
    [super setFrame:frame]
}
于 2013-07-12T19:20:28.953 に答える