美文网首页iOS 进阶
iOS:Xib屏幕适配

iOS:Xib屏幕适配

作者: 春暖花已开 | 来源:发表于2018-12-23 11:42 被阅读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

相关文章

网友评论

    本文标题:iOS:Xib屏幕适配

    本文链接:https://www.haomeiwen.com/subject/kragkqtx.html