私StoryBoard
はiPhone4の解像度用に構成されており、iPhone 5で実行する場合、UIViewを大きくしたいと思います(高さと幅の両方)。
現在の問題は、ビューが高くなるだけで、広くならないことです。これを実現するには、自動サイズ変更の構成はどうすればよいですか?
私StoryBoard
はiPhone4の解像度用に構成されており、iPhone 5で実行する場合、UIViewを大きくしたいと思います(高さと幅の両方)。
現在の問題は、ビューが高くなるだけで、広くならないことです。これを実現するには、自動サイズ変更の構成はどうすればよいですか?
画面の高さを参照し、いくつかのパディング値を使用してビュー フレームを設定します。以下は、と呼ばれる 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);
フレームの変更をキャッチするには、オーバーライドされ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]
}