I want to set text field , uibutton, label and image view at the center of UIView automatically when i chang开发者_StackOverflow社区e mode of view either land scape or portrait mode.My mean that when i change orientation then text field and button and image automatically set in center of view. How i set them by using interface builder or dynamically?
Write code in this method
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if (fromInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || fromInterfaceOrientation == UIInterfaceOrientationLandscapeRight )
{
//write your code specific to orientation
}
else if(fromInterfaceOrientation == UIInterfaceOrientationPortrait || fromInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
{
//write your code specific to orientation
}
}
Programmtically you can set the center
property of your views. Do that when you detect interface orientation change.
you have to constrcut two different frames for that. One for normal view and other for landscape view . Then in the interFaceOrientationChange method u have to set the new frame.
use button.center = view.center property.
use autoresizing
property on UIView and set it accordingly ... most convenient way of doing it
精彩评论