iOS开发之字体大小适配实现
来源:互联网 发布:8选1数据选择器74ls151 编辑:程序博客网 时间:2024/05/16 04:38
一个iOS开发项目无外乎就是纯代码布局、xib或SB布局。那么如何实现两个方式的字体大小适配呢?
字体大小适配------纯代码
#define SizeScale (SCREEN_WIDTH != 414 ?1 :1.2)
#define kFont(value) [UIFont systemFontOfSize:value * SizeScale]
宏中的1.2是在plus下的大小放大比例。
纯代码中设置字体大小通过使用这个宏来实现整体适配
字体大小适配------xib或SB
#import <UIKit/UIKit.h>
#import <objc/runtime.h>
/**
* button
*/
@interface UIButton (MyFont)
@end
/**
* Label
*/
@interface UILabel (myFont)
@end
/**
* TextField
*/
@interface UITextField (myFont)
@end
/**
* TextView
*/
@interface UITextView (myFont)
@end
.m
#import "UIButton+MyFont.h"
//不同设备的屏幕比例(当然倍数可以自己控制)
@implementation UIButton (MyFont)
+ (void)load{
Method imp = class_getInstanceMethod([selfclass], @selector(initWithCoder:));
Method myImp = class_getInstanceMethod([selfclass], @selector(myInitWithCoder:));
method_exchangeImplementations(imp, myImp);
}
- (id)myInitWithCoder:(NSCoder*)aDecode{
[self myInitWithCoder:aDecode];
if (self) {
//部分不像改变字体的把tag值设置成333跳过
if(self.titleLabel.tag !=333){
CGFloat fontSize =self.titleLabel.font.pointSize;
self.titleLabel.font = [UIFontsystemFontOfSize:fontSize * SizeScale];
}
}
return self;
}
@end
@implementation UILabel (myFont)
+ (void)load{
Method imp = class_getInstanceMethod([selfclass], @selector(initWithCoder:));
Method myImp = class_getInstanceMethod([selfclass], @selector(myInitWithCoder:));
method_exchangeImplementations(imp, myImp);
}
- (id)myInitWithCoder:(NSCoder*)aDecode{
[self myInitWithCoder:aDecode];
if (self) {
//部分不像改变字体的把tag值设置成333跳过
if(self.tag !=333){
CGFloat fontSize =self.font.pointSize;
self.font = [UIFontsystemFontOfSize:fontSize * SizeScale];
}
}
return self;
}
@end
@implementation UITextField (myFont)
+ (void)load{
Method imp = class_getInstanceMethod([selfclass], @selector(initWithCoder:));
Method myImp = class_getInstanceMethod([selfclass], @selector(myInitWithCoder:));
method_exchangeImplementations(imp, myImp);
}
- (id)myInitWithCoder:(NSCoder*)aDecode{
[self myInitWithCoder:aDecode];
if (self) {
//部分不像改变字体的把tag值设置成333跳过
if(self.tag !=333){
CGFloat fontSize =self.font.pointSize;
self.font = [UIFontsystemFontOfSize:fontSize * SizeScale];
}
}
return self;
}
@end
@implementation UITextView (myFont)
+ (void)load{
Method imp = class_getInstanceMethod([selfclass], @selector(initWithCoder:));
Method myImp = class_getInstanceMethod([selfclass], @selector(myInitWithCoder:));
method_exchangeImplementations(imp, myImp);
}
- (id)myInitWithCoder:(NSCoder*)aDecode{
[self myInitWithCoder:aDecode];
if (self) {
//部分不像改变字体的把tag值设置成333跳过
if(self.tag !=333){
CGFloat fontSize =self.font.pointSize;
self.font = [UIFontsystemFontOfSize:fontSize * SizeScale];
}
}
return self;
}
@end
- iOS开发之字体大小适配实现
- iOS 字体大小适配
- IOS开发中字体大小
- ios字体大小适配(Category)
- ios开发之修改UITabBarItem的默认字体大小、颜色
- ios笔记 可视化编程字体大小适配
- iOS不同屏幕适配字体大小
- iOS开发—使用TYAttributedLabel实现字体大小颜色各异并且带链接的文本
- iOS开发webView设置字体大小的方法
- IOS开发的字体大小设置有几种方法
- iOS开发之设置导航栏标题的字体大小和颜色
- iOS开发 - 新特性的坑之应用字体根据系统字体大小而变化
- iOS字体大小适配的几种方法
- iOS字体大小适配的几种方法
- ios开发之倒计时实现
- iOS开发之widget实现
- ios 开发之widget实现
- runtime字体大小适配
- 学习笔记之自定义控件
- org.apache.catalina.core.StandardHostValve.customException Processing ErrorPage[errorCode=500, locat
- 理解RESTful架构
- jsp页面的数显示两位小数
- Unable to launch the Java Virtual Machine Located at path: ..\..\jdk\jre\bin\client\jvm.dll
- iOS开发之字体大小适配实现
- yum命令
- java 常用集合list与Set、Map区别及适用场景总结
- 利用快排思想找出数组中第k大的元素
- 自动化部署java的war应用到tomcat脚本
- MySQL双主热备问题处理
- 8月份项目开发之后总结
- JS中日期格式化,加一天加一月等等
- Apache Kafka编程入门指南:Producer