Friday, 8 January 2016

Set Orientation in View

Set Orientation in View




@property (strong, nonatomic) IBOutlet UILabel *Lable1;
@property (strong, nonatomic) IBOutlet UILabel *Label2;

@property (strong, nonatomic) IBOutlet UIButton *button1;
@property (strong, nonatomic) IBOutlet UIImageView *imgview;




- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    if(([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeLeft) || ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeRight))
    {
        [_Lable1 setFrame:CGRectMake(131, 31, 218, 30)];
        [_Lable1 setFrame:CGRectMake(131, 82, 218, 30)];
        
        _button1.frame = CGRectMake(173, 161, 110, 43);
        
        [_imgview setFrame:CGRectMake(0,225,488,46)];
    }
    else if(([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortrait) || ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortraitUpsideDown))
    {
        [_Lable1 setFrame:CGRectMake(131, 31, 218, 30)];
        [_Lable1 setFrame:CGRectMake(131, 82, 218, 30)];
        
        _button1.frame = CGRectMake(173, 161, 110, 43);
        
        [_imgview setFrame:CGRectMake(0,225,488,46)];
    }
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
    if(([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeLeft) || ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationLandscapeRight))
    {
        [_Lable1 setFrame:CGRectMake(131, 31, 218, 30)];
        [_Lable1 setFrame:CGRectMake(131, 82, 218, 30)];
        
        _button1.frame = CGRectMake(173, 161, 110, 43);
        
        [_imgview setFrame:CGRectMake(0,225,488,46)];
    }
    else if(([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortrait) || ([[UIApplication sharedApplication] statusBarOrientation] == UIDeviceOrientationPortraitUpsideDown))
    {
        [_Lable1 setFrame:CGRectMake(131, 31, 218, 30)];
        [_Lable1 setFrame:CGRectMake(131, 82, 218, 30)];
        
        _button1.frame = CGRectMake(173, 161, 110, 43);
        
        [_imgview setFrame:CGRectMake(0,225,488,46)];
    }
}



No comments:

Post a Comment