Button 设置适应不同版本 旋转以后大小相应的改变

很多时候对于不同的版本,随设备的旋转以后,相应的Button的大小如果不做相应的改变,这很影响视图的美观和布局;下面是小编的个人看法

 UIButton *button = [[UIBtton alloc]init];

button.frame =CGRectMake(320/2-100/2,60,100,80);

button.tag = 101;

[button setTitle:@"present"  forState:UIControlStateNormal];

buttton.backgroundColor =[UIColor  redColor];

[button addTarget:self  action:@selector(presentModalVC) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button];

 

 

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration

{

NSLog(@"duration:%f",duration);

UIView *button =[slef.view viewWithTag:101];

if(toInterfaceOrientation==UIInterfaceOrientationMaskPortrait){     

  button.frame =CGRectMake(320/2-100/220010060);//power键向下的时候 

}else{

  

button.frame =CGRectMake(480/2-100/220010060);//这时设备旋转后,原来的长宽调换了

 

 

 

}

}

如果你有更好的方法或者疑问的话 请加QQ:1649419270  微信:meixianLYD

posted @ 2015-05-10 21:53  meixianLYD  阅读(448)  评论(0编辑  收藏  举报