码迷,mamicode.com
首页 > 其他好文 > 详细

CGRectMake1手动适配

时间:2015-09-10 11:21:30      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:

CG_INLINE CGRect
CGRectMake1(CGFloat x, CGFloat y, CGFloat width, CGFloat height)
{
    [[ScreenScale shareScreenScale] getScale];
    CGRect rect;
    rect.origin.x = x * [ScreenScale shareScreenScale].autoSizeScaleX; rect.origin.y = y * [ScreenScale shareScreenScale].autoSizeScaleY;
    rect.size.width = width * [ScreenScale shareScreenScale].autoSizeScaleX; rect.size.height = height * [ScreenScale shareScreenScale].autoSizeScaleY;
    return rect;
}
//
//ScreenScale.h
//
#import <Foundation/Foundation.h>
@interface ScreenScale : NSObject
@property float autoSizeScaleX;
@property float autoSizeScaleY;
+(ScreenScale *)shareScreenScale;
-(void)getScale;
@end
//
//  ScreenScale.m
//
#import "ScreenScale.h"
static ScreenScale * scale;
@implementation ScreenScale
#define ScreenHeight [[UIScreen mainScreen] bounds].size.height//获取屏幕高度,兼容性测试
#define ScreenWidth [[UIScreen mainScreen] bounds].size.width//获取屏幕宽度,兼容性测试
+(ScreenScale *)shareScreenScale
{
    if (scale == nil)
    {
        scale = [[ScreenScale alloc]init];
    }
    return scale;
}
-(void)getScale
{
    if(ScreenHeight > 480){
        self.autoSizeScaleX = ScreenWidth/320;
        self.autoSizeScaleY = ScreenHeight/568;
    }else{
        self.autoSizeScaleX = 1.0;
        self.autoSizeScaleY = 1.0;
    }
}
@end

CGRectMake1手动适配

标签:

原文地址:http://my.oschina.net/wupengnash/blog/504203

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!