老代码: 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;
}