微信字体尺寸适配:
https://mp.weixin.qq.com/s?__biz=MzAwNDY1ODY2OQ==&mid=207113485&idx=1&sn=c49615df4092cfc45a849d2e791fe5d8&scene=1&srcid=05042VAYQkR4KYdlTqltSmYh&pass_ticket=SCmaTqaAWpOx8%2Flb04ID22I49voiHBn1E%2B5oh7jKkD8%3D#rd

一文让你彻底了解iOS字体相关知识
http://www.cnblogs.com/dsxniubility/p/4699352.html

目前为止,iPhone屏幕尺寸已经有四种:

3.5(inch):1/3G/3GS/4/4S

4.0(inch):5/5S/5C

4.7(inch):6

5.5(inch):6Plus

看一下iPhone4~6(+)的屏幕高宽比:

iPhone4(s):分辨率960*640,高宽比1.5
iPhone5(s):分辨率1136*640,高宽比1.775
iPhone6:分辨率1334*750,高宽比1.779
iPhone6+:分辨率1920*1080,高宽比1.778

可粗略认为iPhone5(s)、6(+)的高宽比是一致的(16:9),即可以等比例缩放。因此可以按宽度适配:
fitScreenWidth= width*(SCREEN_WIDTH/320)
这样,共有iPhone3/4/5、6、6+三组宽度,在iPhone6、6+下将按比例横向放大,也就是说我们要适配宽、高、字号大小(如果说Android屏幕适配是地狱一般,那目前来看iPhone屏幕适配还是很美好的)

适配思路

现在产品设计稿有以iPhone5为基准的,也有以iPhone6为基准的,其实没太大影响,因为iPhone5、6、6P的屏幕尺寸比例几乎一样的,所以以iPhone5为基准标注的尺寸,那适配的方法如下:

#define kScreenWidthRatio  (kScreenWidth / 320.0)
#define kScreenHeightRatio (kScreenHeight / 568.0)
#define AdaptedWidthValue(x)  (ceilf((x) * kScreenWidthRatio))
#define AdaptedHeightValue(x) (ceilf((x) * kScreenHeightRatio))

其实就是计算一个比例,然后iPhone6、6P等比放大,这样就保持了iPhone5、6、6P屏幕视觉效果上的一致了。
控件尺寸思路搞定了,但仅仅控件等比例拉伸,其中的内容也要去适应,例如UILabel的字体大小适应,其实也很简单:

#define kUHSystemFontWithSize(R)     [UIFont fontWithName: kULSystemFont size: (AdaptedWidthValue(R))]

实践
有了思路之后,实践一下看看效果,首先看一下最终目标效果图:
置顶
iOS开发~iPhone6及iPhone6P的UI适配

Demo简介:

1、利用TableView展示数据,其中TableView的headerView是滚动的广告,整体UI布局使用相对布局(Autolayout);

2、Autolayout用的是代码实现方式,借助与第三方库Masonry;

3、headerView的滚动广告实现是借助于第三方库SDCycleScrollView;

4、图片下载借助与第三方库SDWebImage;

5、UITableViewCell的自适应高度借助与第三方库UITableView+FDTemplateLayoutCell实现。

新建项目

使用Xcode新建项目后,由于使用到很多第三方,所以使用CocoPods,其中修改Podfile:

platform :ios, ‘7.0’
pod ‘Masonry’
pod ‘SDCycleScrollView’
pod ‘UITableView+FDTemplateLayoutCell’
pod ‘SDWebImage’

实现TableView
1、创建TableView,命名为newslistView:

@property (nonatomic, strong) UITableView *newslistView;

具体实现不说了,介绍一下TableView的布局,这里TableView沾满ViewController的View:
[self.newslistView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];

2、实现TableViewHeader
- (void) loadTableViewHeaderView {
SDCycleScrollView * cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, AdaptedHeightValue(SDCycleScrollViewHeight)) imageURLStringsGroup:nil]; // 模拟网络延时情景
cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
cycleScrollView.delegate = self;
cycleScrollView.showPageControl = YES;
cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
cycleScrollView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
cycleScrollView.dotColor = [UIColor whiteColor]; // 自定义分页控件小圆标颜色
cycleScrollView.placeholderImage = [UIImage imageNamed:@”detail_top”];
[self.view addSubview:cycleScrollView];

cycleScrollView.imageURLStringsGroup = [self.dataDictionary valueForKey:@"advertisement"];self.newslistView.tableHeaderView = cycleScrollView;

}

这里使用到了 AdaptedHeightValue(SDCycleScrollViewHeight)来适应屏幕尺寸,4/4S设备的TableViewHeader高度就小一些,6和6P的TableViewHeader高度就大一些,因为我们是已5代设备为参考实现的产品设计稿。
3、实现TableViewCell

#define UI_DEBUG 0#define ULAppearanceFontSizeMiddle 13
#define ULAppearanceFontSizeSmall  12NSString  *const NewsListCellIdentifier = @"NewsListCellIdentifier";static const CGFloat ULNewsListCellNewsimageViewMarginLeft = 10.0;
static const CGFloat ULNewsListCellNewsimageViewWidth = 100.0;
static const CGFloat ULNewsListCellNewsimageViewHeight = 80.0;static const CGFloat ULNewsListCellTitleLabelMarginTop = 10.0;
static const CGFloat ULNewsListCellTitleLabelMarginLeft = 10.0;
static const CGFloat ULNewsListCellTitleLabelMarginRight = 10.0;
static const CGFloat ULNewsListCellTitleLabelHeight = 20.0;static const CGFloat ULNewsListCellContentLabelMarginTop = 10.0;
static const CGFloat ULNewsListCellContentLabelMarginBottom = 10.0;static const CGFloat ULNewsListCellLineViewMarginLeft = 10.0;
static const CGFloat ULNewsListCellLineViewMarginRight = 10.0;
static const CGFloat ULNewsListCellLineViewHeight = 0.5;@interface NewsListCell ()@property (nonatomic, strong) UIImageView *newsImageView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *contentLabel;
@property (nonatomic, strong) UIView *lineView;@end@implementation NewsListCell- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
#if UI_DEBUGself.contentView.backgroundColor = [UIColor redColor];
#endif[self.contentView addSubview:self.newsImageView];[self.contentView addSubview:self.titleLabel];[self.contentView addSubview:self.contentLabel];[self.contentView addSubview:self.lineView];[self makeConstraintSubviews];}return self;
}- (void) makeConstraintSubviews {[self.newsImageView mas_makeConstraints:^(MASConstraintMaker *make) {make.left.equalTo(self.contentView.mas_left).offset(AdaptedWidthValue(ULNewsListCellNewsimageViewMarginLeft));make.size.mas_equalTo(CGSizeMake(AdaptedWidthValue(ULNewsListCellNewsimageViewWidth), AdaptedHeightValue(ULNewsListCellNewsimageViewHeight)));make.centerY.equalTo(self.contentView.mas_centerY);}];[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.top.equalTo(self.contentView.mas_top).offset(AdaptedHeightValue(ULNewsListCellTitleLabelMarginTop));make.left.equalTo(self.newsImageView.mas_right).offset(AdaptedWidthValue(ULNewsListCellTitleLabelMarginLeft));make.right.equalTo(self.contentView.mas_right).offset(-AdaptedWidthValue(ULNewsListCellTitleLabelMarginRight));make.height.mas_equalTo(AdaptedHeightValue(ULNewsListCellTitleLabelHeight));
//        make.bottom.equalTo(self.contentLabel.mas_top).offset(-AdaptedHeightValue(ULNewsListCellContentLabelMarginTop));}];[self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {make.left.right.equalTo(self.titleLabel);make.top.equalTo(self.titleLabel.mas_bottom).offset(AdaptedHeightValue(ULNewsListCellContentLabelMarginTop));make.bottom.equalTo(self.lineView.mas_bottom).offset(-AdaptedHeightValue(ULNewsListCellContentLabelMarginBottom));}];[self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {make.bottom.equalTo(self.contentView.mas_bottom).offset(-ULNewsListCellLineViewHeight);make.left.equalTo(self.contentView.mas_left).offset(AdaptedWidthValue(ULNewsListCellLineViewMarginLeft));make.right.equalTo(self.contentView.mas_right).offset(-AdaptedWidthValue(ULNewsListCellLineViewMarginRight));;make.height.mas_equalTo(ULNewsListCellLineViewHeight);}];
}- (void)configureWithData:(News *) news {[self.newsImageView sd_setImageWithURL:[NSURL URLWithString:news.imageUrl]];self.titleLabel.text = news.title;self.contentLabel.text = news.content;
}#pragma mark - Getters- (UIImageView *) newsImageView {if (!_newsImageView) {_newsImageView = [[UIImageView alloc] init];
#if UI_DEBUG_newsImageView.backgroundColor = [UIColor greenColor];
#endif}return _newsImageView;
}- (UILabel *) titleLabel {if (!_titleLabel) {_titleLabel = [[UILabel alloc] init];_titleLabel.font = kUHSystemFontWithSize(ULAppearanceFontSizeMiddle);_titleLabel.textColor = [UIColor blackColor];#if UI_DEBUG_titleLabel.backgroundColor = [UIColor lightGrayColor];
#endif}return _titleLabel;
}- (UILabel *) contentLabel {if (!_contentLabel) {_contentLabel = [[UILabel alloc] init];_contentLabel.font = kUHSystemFontWithSize(ULAppearanceFontSizeSmall);_contentLabel.textColor = [UIColor grayColor];_contentLabel.numberOfLines = 0;_contentLabel.lineBreakMode = NSLineBreakByWordWrapping;_contentLabel.textAlignment = NSTextAlignmentLeft;#if UI_DEBUG_contentLabel.backgroundColor = [UIColor brownColor];
#endif}return _contentLabel;
}- (UIView *) lineView {if (!_lineView) {_lineView = [[UIView alloc] init];_lineView.backgroundColor = [UIColor lightGrayColor];}return _lineView;
}@end

iOS 字体适配(转)相关推荐

  1. iOS 字体适配的几种方法总结

    在iOS开发中,有些公司对字体也有适配要求,为了让字体美观,所以在不同尺寸的屏幕上字体大小也要做到适配. 自己总结了几种方法供大家参考. 方法一:用宏定义适配字体大小(根据屏幕尺寸判断) //宏定义 ...

  2. iOS字体大小适配的几种方法

    摘要:在iOS开发中,有些公司对字体也有适配要求,为了让字体美观,所以在不同尺寸的屏幕上字体大小也要做到适配. 自己总结了几种方法供大家参考. 方法一:用宏定义适配字体大小(根据屏幕尺寸判断) //宏 ...

  3. iOS字体大小适配机型的几种方法

    在iOS开发中,有些公司对字体也有适配要求,为了让字体美观,所以在不同尺寸的屏幕上字体大小也要做到适配. 自己总结了几种方法供大家参考. 方法一:用宏定义适配字体大小(根据屏幕尺寸判断) //宏定义 ...

  4. html5开发之ios屏幕适配,iOS开发屏幕尺寸以及屏幕适配等问题(转载内容)

    原帖地址:http://blog.csdn.net/phunxm/article/details/42174937/ 仅供我个人收藏学习,原博主如不同意请联系qq651263878进行删除,在此表示感 ...

  5. iOS 9 适配中出现的坑

    整理 iOS 9 适配中出现的坑(图文) 2015-10-22 iOS开发 库克表示:"现在在中国有150多万的开发者在iOS当中开发应用程序,我们鼓励更多的人开发应用程序,也鼓励更多的创业 ...

  6. iOS 屏幕适配浅谈

    作者 | 钱凯 杏仁移动开发工程师,前嵌入式工程师,关注大前端技术新潮流. 前端开发的屏幕适配其实算是基本功,每个码农在长期实践中都有自己的总结. 在 iOS 平台上,苹果爸爸对适配的支持个人感觉很不 ...

  7. iOS 13适配汇总

    随着iPhone 11的发布,iOS 13适配也提上了日程,接下来就开发中升级iOS13的手机可能出现的问题 Xcode: 11.0 iOS : 13.0 UIViewController 模态弹出界 ...

  8. IOS 屏幕适配(一)理论篇

    IOS 屏幕适配(一)理论篇 1. IOS 屏幕适配基本概念 1.1 IOS 设备的尺寸和分辨率 1.1.1 分辨率相关概念 1.1.2 IOS 各个设备对应的分辨率 1.2 设计和开发之间的多屏适配 ...

  9. Android面试题-解决字体适配

    源码分析相关面试题 Volley源码分析 注解框架实现原理 okhttp3.0源码分析 onSaveInstanceState源码分析 Activity相关面试题 保存Activity的状态 acti ...

最新文章

  1. oc 计算 带括号 式子
  2. Java URL传参中文乱码问题
  3. JZOJ 5603. 【NOI2018模拟3.27】Xjz
  4. CVPR 2020 | ActBERT: 自监督多模态视频文字学习
  5. 153. 寻找旋转排序数组中的最小值 golang
  6. 【php-laravel框架】第三节:利用composer安装laravel-admin开源管理系统
  7. 一条数据的HBase之旅,简明HBase入门教程1:开篇
  8. 事务的四个属性ACID
  9. stl:sort(stl快速排序)
  10. seo优化之如何选择产品
  11. 安川机器人如何注释化指令_关于安川机器人I/O注释导入的报告
  12. tictac 立体井字棋
  13. iP138查询网,ip数据库
  14. Photoshop - 关于在 PS 中使用渐变会产生条纹色阶的问题
  15. PTA 7-24 书香节
  16. 北京理工大学汇编语言复习重点(可打印)
  17. Joplin+七牛云+vscode 免费云端同步笔记工具(跨平台)
  18. 网页加载慢,Initial connection请求偶尔过长
  19. 求解!!急急急!!!
  20. 行测-数量关系-解题技巧-代入排除法

热门文章

  1. 学习笔记——数据格式的变更和自定义
  2. 加密内存卡 TF 卡歌曲或资料拷贝出来的方法,完全可行!
  3. 全网最全可视化大屏模板
  4. Flutter 底部导航栏(Tab 页)的快速实现
  5. win10怎么下载python_w10怎么下载安装python|w10下载安装python的方法
  6. nginx+php https 实践
  7. 人工衍射透镜的设计与分析
  8. 帝国CMS仿精美的茶杯狐电影网站源码+手机电脑自适应+电影电视剧动漫演员剧情综艺
  9. 机器学习笔记之指数族分布——最大熵原理与softmax激活函数的关系
  10. 华为、中兴、联想、百度们,盯上了路边的灯杆