开发者

How set text field and button at center of view automatically when mode change?

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜