zoukankan      html  css  js  c++  java
  • 如何处理UIVIew addsubview 不显示subview

    老代码: addsubview不显示uilabel
    -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,tableView.frame.size.width,50)];
        UILabel *label=[[UILabel new]initWithFrame:CGRectMake(0, 0 ,200, 50)];
    
        label.text=@"加载更多...";
        label.textColor=[UserSetting getIntance].titleColor;
        label.backgroundColor=[UserSetting getIntance].titleColor;
        [view addSubview:label];
         [view setBackgroundColor:[UserSetting getIntance].mainColor];
        return view;
    }
    原因在于:addsubview 没有使 UILabel的大小生效
    需要在addsuview后面再赋值frame.
    新代码如下
    -(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    {
        UIView *view = [[UIView alloc]     initWithFrame:CGRectMake(0,0,tableView.frame.size.width,50)];
        UILabel *label=[[UILabel new]init];
    
        label.text=@"加载更多...";
        label.textColor=[UserSetting getIntance].titleColor;
        label.backgroundColor=[UserSetting getIntance].titleColor;
        [view addSubview:label];
        label.frame=CGRectMake(0, 0 ,200, 50);
        [view setBackgroundColor:[UserSetting getIntance].mainColor];
        return view;
    }
    

      

  • 相关阅读:
    AtCoder Regular Contest 093
    AtCoder Regular Contest 094
    G. Gangsters in Central City
    HGOI 20190711 题解
    HGOI20190710 题解
    HGOI 20190709 题解
    HGOI 20190708 题解
    HGOI20190707 题解
    HGOI20190706 题解
    HGOI 20190705 题解
  • 原文地址:https://www.cnblogs.com/Zoes/p/5117587.html
Copyright © 2011-2022 走看看