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