AutoLayoutCommon(适用于xib和storyboard布局)

#import 

"AutoLayoutCommon.h"#import#define Kscr KscrW/375

#define KscrW [UIScreen mainScreen].bounds.size.width

@implementation AutoLayoutCommon

+(void)autolayoutWithArray:(NSArray *)subviewsArray

{

[subviewsArray enumerateObjectsUsingBlock:^(UIView *obj, NSUInteger idx, BOOL *stop) {

if (obj.subviews.count==0) {

[ AutoLayoutCommon changefram:obj width:idx];

}else

{

[ AutoLayoutCommon changefram:obj width:idx];

[self autolayoutWithArray:obj.subviews];

}

}];

}

+(void)changefram:(UIView *)obj width:(NSUInteger)idx

{

obj.frame = CGRectMake(obj.frame.origin.x*Kscr, obj.frame.origin.y*Kscr, obj.frame.size.width*Kscr, obj.frame.size.height*Kscr);

if ([obj isKindOfClass:[UILabel class]]||[obj isMemberOfClass:[UITextField class]]||[obj isMemberOfClass:[UITextView class]]) {

UILabel *label = (UILabel *)obj;

CGFloat size = label.font.pointSize;

label.font = [UIFont systemFontOfSize:size*Kscr];

}

if ([obj isKindOfClass:[UIButton class]]) {

UIButton *btn = (UIButton*)obj;

//            btn.layer.masksToBounds = YES;

//            btn.layer.cornerRadius = 5*Kscr;

UILabel *label = btn.titleLabel;

CGFloat size = label.font.pointSize;

label.font = [UIFont systemFontOfSize:size*Kscr];

}

}

@end


#import

@interface AutoLayoutCommon : NSObject

+(void)autolayoutWithArray:(NSArray *)subviewsArray;

@end

你可能感兴趣的:(AutoLayoutCommon(适用于xib和storyboard布局))