全局修改Lable/Button字体
#ifndef SwizzlingExchange_h
#define SwizzlingExchange_h
#import <objc/runtime.h> static inline void swizzling_exchangeMethod(Class clazz, SEL originalSelector, SEL swizzledSelector) {
Method originalMethod = class_getInstanceMethod(clazz, originalSelector);
Method swizzledMethod = class_getInstanceMethod(clazz, swizzledSelector); BOOL success = class_addMethod(clazz, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod)); if (success) {
class_replaceMethod(clazz, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
} #endif /* SwizzlingExchange_h */
//
// UILabel+ChangeFont.m
// DFRomwe
//
// Created by 王卫亮 on 16/7/13.
// Copyright © 2016年 heyan. All rights reserved.
// #import "UILabel+ChangeFont.h"
#import "SwizzlingExchange.h" #define kLableFont @"Snell Roundhand" // 测试字体,容易看出来有没有全改掉 @implementation UILabel (ChangeFont) +(void)load {
//只执行一次这个方法
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
swizzling_exchangeMethod([self class], @selector(init), @selector(myInit));
swizzling_exchangeMethod([self class], @selector(initWithFrame:), @selector(myInitWithFrame:));
swizzling_exchangeMethod([self class], @selector(awakeFromNib), @selector(myAwakeFromNib));
});
} - (instancetype)myInit {
id __self = [self myInit];
UIFont * font = [UIFont fontWithName:DefaultFont size: self.font.pointSize];
if (font) {
self.font = font;
}
return __self;
} - (instancetype)myInitWithFrame:(CGRect)rect {
id __self = [self myInitWithFrame: rect];
UIFont * font = [UIFont fontWithName:DefaultFont size: self.font.pointSize];
if (font) {
self.font = font;
}
return __self;
} - (void)myAwakeFromNib {
[self myAwakeFromNib];
UIFont * font = [UIFont fontWithName:DefaultFont size: self.font.pointSize];
if (font) {
self.font = font;
}
} @end
Button:
//
// UIButton+ChangeFont.m
// DFRomwe
//
// Created by 王卫亮 on 16/7/13.
// Copyright © 2016年 heyan. All rights reserved.
// #import "UIButton+ChangeFont.h"
#import "SwizzlingExchange.h" #define kLableFont @"Snell Roundhand" // 测试字体,容易看出来有没有全改掉 @implementation UIButton (ChangeFont) +(void)load {
//只执行一次这个方法
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
swizzling_exchangeMethod([self class], @selector(init), @selector(myInit));
swizzling_exchangeMethod([self class], @selector(initWithFrame:), @selector(myInitWithFrame:));
swizzling_exchangeMethod([self class], @selector(awakeFromNib), @selector(myAwakeFromNib));
});
} - (instancetype)myInit { id __self = [self myInit];
UIFont * font = [UIFont fontWithName:DefaultFont size: self.titleLabel.font.pointSize];
if (font) {
self.titleLabel.font = font;
}
return __self;
} - (instancetype)myInitWithFrame:(CGRect)rect {
id __self = [self myInitWithFrame:rect];
UIFont * font = [UIFont fontWithName:DefaultFont size: self.titleLabel.font.pointSize];
if (font) {
self.titleLabel.font = font;
}
return __self;
} - (void)myAwakeFromNib {
[self myAwakeFromNib];
UIFont * font = [UIFont fontWithName:DefaultFont size: self.titleLabel.font.pointSize];
if (font) {
self.titleLabel.font = font;
}
} @end
全局修改Lable/Button字体的更多相关文章
- iOS运用runtime全局修改UILabel的默认字体
iOS运用runtime全局修改UILabel的默认字体 一.需求背景介绍 在项目比较成熟的基础上,遇到了这样一个需求,应用中需要引入新的字体,需要更换所有Label的默认字体,但是同时,对于一些特殊 ...
- 修改美化Matlab字体
修改美化Matlab字体 MATLAB作为高校理工科类本科生或研究生必不可少的科研工具已经有着很多年的历史,以至于在我们的大学生活里或科研工作中,MATLAB处处闪现着它的身影,给我们带来了不少 ...
- delphi 修改Hint的字体和颜色
//修改Hint的字体和颜色 public { Public declarations } procedure Sshowhint(var hintstr:string;var can ...
- Android Studio 3.1.2 修改字体(font)大小(size) 及老版本修改主题、字体、颜色 参照地址
Android Studio 3.1.2 修改字体(font)大小(size) 步骤:File-Settings-Editor-Color Scheme-Color Scheme Font-Size ...
- idea 修改编辑区字体样式、大小
idea 修改编辑区字体样式.大小 CreateTime--2018年4月26日10:36:59 Author:Marydon 设置-->Editor-->Font-->修改Fo ...
- 修改eclipse 代码字体大小以及文档字体大小
1..点击[window]在弹出的窗口中选择[preferences] 2.在弹出窗口中找到依次点击General(常规)——Apprearance(外观)——Colors and Fonts(颜色和 ...
- Android系统移植与调试之------->如何修改Android默认字体大小和设置里面字体大小比例
因为我修改 ro.sf.lcd_density的值,将它从160修改 为120,所以导致整个系统的字体都变得很小.因此需要将整个字体变大,并且在设置-->显示-->字体大小的4个选项的值都 ...
- 李洪强iOS开发之-修改状态栏的字体的颜色
李洪强iOS开发之-修改状态栏的字体的颜色 修改的效果: -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; [ ...
- 线程全局修改、死锁、递归锁、信号量、GIL以及多进程和多线程的比较
线程全局修改 x = 100 def func1(): global x print(x) changex() print(x) def changex(): global x x = 50 func ...
随机推荐
- IIS+PHP配置一次成功无错误版
1.首先去PHP官网下载php的压缩包(.zip),由于web服务器是IIS所以尽量使用线程不安全版本的,我下载的是: VC11 x86 Non Thread Safe (2015-May-14 18 ...
- 1、android源代码下载及目录分析,和eclipser的跟踪
1.在eclipse中跟踪源代码:假如对mainactivity.java里面的activity按Ctrl+鼠标左键(前提已经导入android源代码:方法1:在项目点击右键,然后找到properti ...
- mysql主从复制配置(精简版)
一.首先准备两台服务器,虚拟机即可,以笔者为例:master:192.168.1.105 slave:192.168.1.106 二.保证两台虚拟机能相互ping通,先把防火墙关闭:service i ...
- 从c开始,小小感悟
c语言是众多编程小白进入编程大门的钥匙,不过许多人在学习一段时间以后就渐渐产生了困惑,枯燥的黑色界面渐渐让他们失去了"渴望",---我还不能制作出一款像样的软件,我还是只是在算数学 ...
- NullReferenceException UnityEngine.Transform.get_localPosition
NullReferenceException UnityEngine.Transform.get_localPosition unity程序中,需要取得GO自身的Transform,出现如上空异常, ...
- LNMP安装一键安装包
系统需求: CentOS/Debian/Ubuntu Linux系统 需要2GB以上硬盘剩余空间 128M以上内存,OpenVZ的建议192MB以上(小内存请勿使用64位系统) VPS或服务器必须已经 ...
- 第三个Sprint冲刺第四天
讨论地点:宿舍 讨论成员:邵家文.李新.朱浩龙.陈俊金 讨论问题:强化界面功能
- ubuntu 14.04 LTS 安装ss客户端
附: 配置pac模式 ss客户端 ss客户端 前提环境 python (用最新的就行) pip (注:python工具) build-essential 以上可以通过一条命令解决: sudo apt- ...
- PAT (Basic Level) Practise:1026. 程序运行时间
[题目链接] 要获得一个C语言程序的运行时间,常用的方法是调用头文件time.h,其中提供了clock()函数,可以捕捉从程序开始运行到clock()被调用时所耗费的时间.这个时间单位是clock t ...
- animate.css 一些常用的CSS3动画效果
大家已经开始在项目中使用一些CSS3动画效果了吧,这让网站在高端浏览器上看起来很上流.animate.css是一个老外做的各种CSS3动画的合集,比较全,也很炫,大家可以参考学习一下. 项目主页:ht ...