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;
    }
    

      

  • 相关阅读:
    swift
    swift
    swift
    swift
    swift
    swift
    swift
    选择排序
    组合 和 继承
    Android中使用LitePal操控SQLite数据库
  • 原文地址:https://www.cnblogs.com/Zoes/p/5117587.html
Copyright © 2011-2022 走看看