iOS 进阶

iOS:Xib屏幕适配

2018-12-23  本文已影响19人  春暖花已开
#import "NSLayoutConstraint+MZExtension.h"

#import <objc/runtime.h>

#define kLayoutConstraintScreenWidth [UIScreen mainScreen].bounds.size.width
#define kLayoutConstraintScale(x) (CGFloat)kLayoutConstraintScreenWidth / 375.0 * x

@implementation NSLayoutConstraint (MZExtension)

+ (void)load {
    
    Method imp = class_getInstanceMethod([self class], @selector(initWithCoder:));
    Method myImp = class_getInstanceMethod([self class], @selector(myInitWithCoder:));
    method_exchangeImplementations(imp, myImp);
}

- (id)myInitWithCoder:(NSCoder *)aDecode {
    
    [self myInitWithCoder:aDecode];
    if (self) {
        
        if (![self.identifier isEqualToString:@"333"]) {
            self.constant = kLayoutConstraintScale(self.constant);
        }
    }
    return self;
}

@end

上一篇 下一篇

猜你喜欢

热点阅读