MBProgressHUD自定义customView


MBProgressHUD 自定义customView 比较简单代码如下:

MBProgressHUD _customHud = [[MBProgressHUD alloc]initWithFrame:MAIN_SCREEN_BOUNDS]; 
_customHud.margin
= 0;
_customHud.customView
= self.noticeView;
_customHud.mode
= MBProgressHUDModeCustomView;

但是你很快就会发现自定义view的frame值不管你怎么设置,都不对,都不是想要的结果上github上,查了一下得到一下结果:

 

1.首先自定义view必须重写:intrinsicContentSize方法

2.手动设置 translatesAutoresizingMaskIntoConstraints = NO

完整代码如下:

#import "GLNoticeView.h"

@implementation GLNoticeView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (CGSize)intrinsicContentSize {
    CGFloat contentViewH = 200;
    CGFloat contentViewW = MAIN_SCREEN_WIDTH - 40;
    return CGSizeMake(contentViewW, contentViewH);
}


- (instancetype)initWithFrame:(CGRect)frame {
   self = [[NSBundle mainBundle] loadNibNamed:@"GLNoticeView" owner:nil options:nil].firstObject;
    self.translatesAutoresizingMaskIntoConstraints = NO;
    self.layer.cornerRadius = 4;
    self.layer.masksToBounds = YES;
    return self;
}

@end

至此问题完美解决。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM