An iOS development project is nothing more than a pure code layout, xib, or SB layout. So how to achieve the two ways of matching the size of the font. Font Size fit------Pure Code definition a macro is defined as follows:
#define Sizescale (screen_width!= 414? 1:1.2)
#define KFONT (value) [Uifont systemfontofsize:value * Sizescale]
The 1.2 in the macro is the magnification of the size under plus.
Set the font size in pure code by using this macro to fit the whole
Font Size fit------xib or SB font size fit no outside is to set the font size of UIButton, Uilabel, Uitextview, Uitextfield By creating these several classes to achieve (runtime way of black Magic method swizzling) nonsense not to say, directly on the code:. h
#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"
screen proportions of different devices (of course multiples can be controlled by themselves)
@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) {
Part is not like changing the font to set the tag value to 333 skip
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) {
Part is not like changing the font to set the tag value to 333 skip
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) {
Part is not like changing the font to set the tag value to 333 skip
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) {
Part is not like changing the font to set the tag value to 333 skip
if (Self.tag!=333) {
CGFloat fontsize =self.font.pointsize;
Self.font = [uifontsystemfontofsize:fontsize * Sizescale];
}
}
return self;
}
@end