iOS -不同模拟器字体适配
1.先建立一个UILabel的分类
导入#import <objc/runtime.h>头文件
2.在.m文件中写入如下代码
//不同设备的屏幕比例(当然倍数可以自己控制)
#define IPHONE_HEIGHT [UIScreen mainScreen].bounds.size.height
#define SizeScale ((IPHONE_HEIGHT > 568) ? IPHONE_HEIGHT/568 : 1)
@implementation UILabel(myFont)
+ (void)load{
Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
method_exchangeImplementations(imp, myImp);
Method cmp = class_getInstanceMethod([self class], @selector(initWithFrame:));
Method myCmp = class_getInstanceMethod([self class], @selector(myInitWithFrame:));
method_exchangeImplementations(cmp, myCmp);
}
- (id)myInitWithCoder:(NSCoder*)aDecode{
[self myInitWithCoder:aDecode];
if (self) {
//部分不像改变字体的 把tag值设置成333跳过
if(self.tag != 333){
CGFloat fontSize = self.font.pointSize;
self.font = [UIFont systemFontOfSize:fontSize * SizeScale];
NSLog(@" label的大小 == %f", self.font.pointSize);
}
}
return self;
}
- (id)myInitWithFrame:(CGRect)frame{
[self myInitWithFrame:frame];
if(self){
CGFloat fontSize = self.font.pointSize;
self.font = [UIFont systemFontOfSize:fontSize * SizeScale];
NSLog(@" label的大小 == %f", self.font.pointSize);
}
return self;
}
@end
3.在调用文件中导入分类
#import "ViewController.h"
#import "UIButton+myFont.h"
@interface ViewController ()
/*注释*/
@property (nonatomic,strong)UILabel *label;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view addSubview:self.label];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewWillAppear:(BOOL)animated
{
NSLog(@"%@",self.label.font);
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UILabel *)label{
if (!_label) {
_label = [[UILabel alloc]initWithFrame:CGRectMake(50, 100, 100, 30)];
// _label.font = [UIFont systemFontOfSize:17];
_label.tag = 32;
_label.text = @"这是测试文字";
}
return _label;
}
@end
iOS -不同模拟器字体适配的更多相关文章
- iOS 4s-6Plus屏幕自动适配及颜色转换为十六进制
iOS各种屏幕自动适配及颜色转换为十六进制 ★★★XLJMatchScreen自动适配屏幕★★★ 支持pod导入 pod 'XLJScreenMatching', '~> 1.0.3' 如果发现 ...
- iOS 向模拟器里添加照片
iOS 向模拟器里添加照片 模拟器里Photos最开始时是没有照片的,有时我们做Demo时需要Photos里面的照片做测试,这时就需要把Mac上的照片导入到模拟器里.步骤如下: 1,打开模拟器 2,选 ...
- iOS 中的字体预览
要预览iOS的各种字体的效果,可以访问http://iosfonts.com
- iOS完整预装字体清单
iOS完整预装字体清单:http://iosfonts.com/
- Android 字体适配方案
开发过程中,按照UI设计尺寸做好UI页面,当用户自定义自己的手机字体大小之后UI完全没法看了,这个时候就在想让app字体大小始终一致就好了 下面看一下,出现的问题和解决方案 做个简单的例子,先 ...
- iOS Simulator 模拟器 与 Android Emulator 仿真器:为什么叫不同的英文名字?(待补充)
iOS Simulator 模拟器 与 Android Emulator 仿真器:为什么叫不同的英文名字?(待补充)
- 显示iOS所有系统字体
显示iOS所有系统字体 源码地址: https://github.com/YouXianMing/UI-Component-Collection 效果图: 便于你开发中寻找适合自己的字体, demo中 ...
- iOS WKWebview 网页开发适配指南
iOS WKWebview 网页开发适配指南 微信iOS客户端将于2017年3月1日前逐步升级为WKWebview内核,需要网页开发者提前做好网站的兼容检查和适配.如有问题,可参考文末联系方式,向我们 ...
- iOS 多尺寸屏幕适配
Point Point可以理解为iOS程序员眼中的大小单位.它是iOS操作系统中的抽象的概念. Rendered Pixels可以理解为UI设计师眼中的大小单位. Physical Pixels 设备 ...
随机推荐
- SWAT—Samba WEB管理工具
本文试验环境是RHEL5.2+samba-swat-3.0.28.Server的IP是192.168.120.241. 1. swat介绍 SWAT:The Samba WEB Administr ...
- sqlclr返回数据集案例
----------------------------------------------返回一张表,但只有一条数据,最后一次设置的. [Microsoft.SqlServer.Server.Sql ...
- httpWebRequest.ContentType 属性、值 类型用法
httpWebRequest.ContentType 属性.值 类型用法 冰火战地 指定将数据回发到服务器时浏览器使用的编码类型.下边是说明: application/x-www-form-urlen ...
- ASP.NET MVC扩展点
16个ASP.NET MVC扩展点[附源码] 1.自定义一个HttpModule,并将其中的方法添加到HttpApplication相应的事件中!即:创建一个实现了IHttpmodule接口的类,并将 ...
- iOS基础 - 瀑布流
一.瀑布流简介 瀑布流,又称瀑布流式布局.是比较流行的一种网站页面布局,视觉表现为参差不齐的多栏布局,随着页面滚动条向下滚动,这种布局还会不断加载数据块并附加至当前尾部.最早采用此布局的网站是Pint ...
- iOS基础 - 核心动画
一.核心动画 l 核心动画基本概念 l 基本动画 l 关键帧动画 l 动画组 l 转场动画 l Core Animation是一组非常强大的动画处理API,使用它能做出非常炫丽的动画效果,而且往往是事 ...
- c# 自定义多选下拉列表2
以下为工作中遇到的,备注一下 先需要几个辅助类 #region GripBounds using System.Drawing; internal struct GripBounds { ; ; pu ...
- c# 发邮件功能
using System;using System.Collections.Generic;using System.Data;using System.Data.SqlClient;using Sy ...
- 使用protobuf编写配置文件以及读写
.proto文件示例 message Configure { required ; required uint32 port = ; } 写配置文件 Configure config; config. ...
- DropDownList单选与多选下拉框
一.单选DropDownList传值 1.添加界面的DropDownList显示值问题 (1)在方法内添加ViewData的方法: var ad = new UnitsRepository(); Vi ...