zoukankan      html  css  js  c++  java
  • 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

    至此问题完美解决。

  • 相关阅读:
    P1631-序列合并
    P1484-种树
    17.树的子结构(python)
    16.合并两个排序的链表(python)
    反转链表
    链表中倒数第k个节点(python)
    调整数组顺序使奇数位于偶数前面(python)
    Spark--wordcount(词频降序)
    数值的整数次方
    二进制中1的个数(python)
  • 原文地址:https://www.cnblogs.com/TengSys/p/6739121.html
Copyright © 2011-2022 走看看