iphone5处理屏幕分辨率

创建轻量UIDivece类别用以处理所有的屏幕分辨率

  1. //  
  2. //  UIDevice+Resolutions.h  
  3. //    
  4. //  
  5. //  Created by HelenSong on 12-9-25.  
  6. //  Copyright (c) 2012年 . All rights reserved.  
  7. //  
  8.   
  9. #import <UIKit/UIKit.h>  
  10.   
  11. enum {  
  12.     UIDevice_iPhoneStandardRes      = 1,    // iPhone 1,3,3GS Standard Resolution   (320x960px)  
  13.     UIDevice_iPhoneHiRes            = 2,    // iPhone 4,4S High Resolution          (640x960px)  
  14.     UIDevice_iPhoneTallerHiRes      = 3,    // iPhone 5 High Resolution             (640x1136px)  
  15.     UIDevice_iPadStandardRes        = 4,    // iPad 1,2 Standard Resolution         (1024x768px)  
  16.     UIDevice_iPadHiRes              = 5     // iPad 3 High Resolution               (2048x1536px)  
  17. }; typedef NSUInteger UIDeviceResolution;  
  18.   
  19. @interface UIDevice (Resolutions) { }  
  20.   
  21. + (UIDeviceResolution) currentResolution;  
  22.   
  23. @end  

  1. //  
  2. //  UIDevice+Resolutions.m  
  3. //    
  4. //  
  5. //  Created by HelenSong on 12-9-25.  
  6. //  Copyright (c) 2012年 . All rights reserved.  
  7. //  
  8.   
  9. #import "UIDevice+Resolutions.h"  
  10.   
  11. @implementation UIDevice (Resolutions)  
  12.   
  13. + (UIDeviceResolution) currentResolution {  
  14.     if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){  
  15.         if ([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) {  
  16.             CGSize result = [[UIScreen mainScreen] bounds].size;  
  17.             result = CGSizeMake(result.width * [UIScreen mainScreen].scale, result.height * [UIScreen mainScreen].scale);  
  18.             return (result.height == 960 ? UIDevice_iPhoneHiRes : UIDevice_iPhoneTallerHiRes);  
  19.         } else  
  20.             return UIDevice_iPhoneStandardRes;  
  21.     } else  
  22.         return (([[UIScreen mainScreen] respondsToSelector: @selector(scale)]) ? UIDevice_iPadHiRes : UIDevice_iPadStandardRes);  
  23. }  
  24.   
  25. @end  

方法二:使用宏定义方式判断是否为iphone5


  1. #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)  

  1. if (!iPhone5) {  
  2.         [[NSBundle mainBundle]loadNibNamed:@"xxxController" owner:self options:nil];    
  3.     }else {  
  4.         [[NSBundle mainBundle]loadNibNamed:@"xxxController4inch" owner:self options:nil];  
  5.     } 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值