您的位置:首页 > 其它

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

2015-05-10 21:53 246 查看
很多时候对于不同的版本,随设备的旋转以后,相应的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/2, 200, 100, 60);//power键向下的时候

}else{

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

}

}

如果你有更好的方法或者疑问的话 请加QQ:1649419270 微信:meixianLYD
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐