AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
AppDelegate *autoSizeDelegate = [[UIApplication sharedApplication] delegate];
if(KScreenHeight > 480){
autoSizeDelegate.autoSizeScaleX = KScreenWidth/320;
autoSizeDelegate.autoSizeScaleY = KScreenHeight/568;
}else{
autoSizeDelegate.autoSizeScaleX = 1.0;
autoSizeDelegate.autoSizeScaleY = 1.0;
}
return YES;
}
AppDelegate.h
@property float autoSizeScaleX;
@property float autoSizeScaleY;
- (void)viewDidLoad {
[super viewDidLoad];
UIView * vie = [[UIView alloc]init];
vie.frame = [SY CGRectMakeX:100 Y:100 W:100 H:100];
vie.backgroundColor = [UIColor redColor];
[self.view addSubview:vie];
}
@implementation SY
+ (CGRect)CGRectMakeX:(CGFloat)x Y:(CGFloat)y W:(CGFloat)width H:(CGFloat)height{
AppDelegate *autoSizeDelegate = [[UIApplication sharedApplication] delegate];
CGRect rect;
rect.origin.x = x * autoSizeDelegate.autoSizeScaleX;
rect.origin.y = y * autoSizeDelegate.autoSizeScaleY;
rect.size.width = width * autoSizeDelegate.autoSizeScaleX;
rect.size.height = height * autoSizeDelegate.autoSizeScaleY;
return rect;
}