UIFont - iOS 글꼴 맞춤
+(void)load{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Method newMethod = class_getClassMethod([self class], @selector(adjustFont:));
Method method = class_getClassMethod([self class], @selector(systemFontOfSize:));
method_exchangeImplementations(newMethod, method);
Method newBoldMethod = class_getClassMethod([self class], @selector(adjustBoldFont:));
Method boldMethod = class_getClassMethod([self class], @selector(boldSystemFontOfSize:));
method_exchangeImplementations(newBoldMethod, boldMethod);
});
}
+ (UIFont *)adjustFont:(CGFloat)fontSize
{
[self adjustFont:fontSize];
UIFont *newFont = nil;
if (iPhone6 || iPhoneX)
{
//iPhone 6|6S|7|7S|8
newFont = [UIFont adjustFont:fontSize + 2];
}
else if (iPhone6Plus)
{
//iPhone 6P|7P|8P
newFont = [UIFont adjustFont:fontSize + 4];
}
else
{
//iPhone 5|5S|5C|4|4S
newFont = [UIFont adjustFont:fontSize];
}
// newFont = [UIFont adjustFont:fontSize * SizeScale];
return newFont;
}
+ (UIFont *)adjustBoldFont:(CGFloat)fontSize {
[self adjustBoldFont:fontSize];
UIFont *newFont = nil;
if (iPhone6 || iPhoneX)
{
//iPhone 6|6S|7|7S|8
newFont = [UIFont adjustBoldFont:fontSize + 2];
}
else if (iPhone6Plus)
{
//iPhone 6P|7P|8P
newFont = [UIFont adjustBoldFont:fontSize + 4];
}
else
{
//iPhone 5|5S|5C|4|4S
newFont = [UIFont adjustBoldFont:fontSize];
}
return newFont;
}
그리고 nib 글꼴 컨트롤, 컨트롤 다 써주세요.
@implementation UILabel (FontSize)
+ (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 < TagNoScale) {
CGFloat fontSize = self.font.pointSize;
if (iPhone6 || iPhoneX)
{
//iPhone 6|6S|7|7S|8
self.font = [self.font fontWithSize:fontSize + 2];
}
else if (iPhone6Plus)
{
//iPhone 6P|7P|8P
self.font = [self.font fontWithSize:fontSize + 4];
}
else
{
//iPhone 5|5S|5C|4|4S
self.font = [self.font fontWithSize:fontSize];
}
}
return self;
}
- (id)myInitWithFrame:(CGRect)frame{
[self myInitWithFrame:frame];
if(self){
if (self.tag < TagNoScale) {
CGFloat fontSize = self.font.pointSize;
if (iPhone6 || iPhoneX)
{
//iPhone 6|6S|7|7S|8
self.font = [self.font fontWithSize:fontSize + 2];
}
else if (iPhone6Plus)
{
//iPhone 6P|7P|8P
self.font = [self.font fontWithSize:fontSize + 4];
}
else
{
//iPhone 5|5S|5C|4|4S
self.font = [self.font fontWithSize:fontSize];
}
}
}
return self;
}
@end
일을 끝내다
가끔 myInitWithFrame 붕괴...참고만
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.