美文网首页
iOS 控件宽高字体大小适配方法

iOS 控件宽高字体大小适配方法

作者: 天地一紫罗 | 来源:发表于2017-03-10 12:34 被阅读0次

    一:

    #define kScreenHeight [UIScreen mainScreen].bounds.size.height

    #define kScreenWith  [UIScreen mainScreen].bounds.size.width

    //当前屏幕与设计尺寸(iPhone6)宽度比例

    @property(nonatomic,assign)CGFloat autoSizeScaleW;

    //当前屏幕与设计尺寸(iPhone6)高度比例

    @property(nonatomic,assign)CGFloat autoSizeScaleH;

    二:

    实现自定义方法- (void)initAutoScaleSize;

    - (CGFloat)initAutoScaleSize{

    //[UIScreen mainScreen].bounds.size.width

    if (kScreenHeight==480) {

    //4s

    self.autoSizeScaleW = kScreenWith/736;

    //_autoSizeScaleH = kScreenHeight/414;

    }else if(kScreenHeight==568) {

    //5

    self.autoSizeScaleW =kScreenWith/736;

    //_autoSizeScaleH =kScreenHeight/414;

    }else if(kScreenHeight==667){

    //6

    self.autoSizeScaleW =kScreenWith/736;

    //_autoSizeScaleH =kScreenHeight/414;

    }else if(kScreenHeight==736){

    //6p

    self.autoSizeScaleW =kScreenWith/736;

    //_autoSizeScaleH =kScreenHeight/414;

    }else if (kScreenHeight==1024){

    self.autoSizeScaleW =kScreenWith/736;

    }else{

    self.autoSizeScaleW=kScreenWith/736;

    }

    return  self.autoSizeScaleW;

    }

    4.写控件时设置字体大小:

    [UIFontsystemFontOfSize:autoScaleW(14)]

    设置frame:

    CGRectMake(CGRectGetMaxX(self.productNameLabel.frame) + 10 , self.productNameLabel.top+3,autoScaleW(32),autoScaleW(17));

    1

    相关文章

      网友评论

          本文标题: iOS 控件宽高字体大小适配方法

          本文链接:https://www.haomeiwen.com/subject/gbamgttx.html