【发布时间】:2014-08-20 21:34:43
【问题描述】:
我正在尝试在 tableView 页脚中将标签和图像居中
我似乎无法让它同时适用于 iPhone 和 iPad 设备
现在它以 iPhone 为中心,但那是因为我对其进行了硬编码。
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 50)];
[view setBackgroundColor:[UIColor clearColor]];
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, self.view.bounds.size.width, 20)];
lbl.lineBreakMode = NSLineBreakByWordWrapping;
lbl.numberOfLines = 0;
[lbl setText:@"Powered By"];
[lbl setFont:[UIFont systemFontOfSize:10]];
[lbl setTextAlignment:NSTextAlignmentCenter];
[lbl setTextColor:[UIColor blackColor]];
District *school = [District new];
UIImageView * logoView = [[UIImageView alloc]initWithFrame:CGRectMake(50, 25, 150, 37.5)];
logoView.image = [UIImage imageNamed:@"Logo.png"];
[logoView autoresizingMask];
[view addSubview:logoView];
[view addSubview:lbl];
return view;
}
我想将此视图居中,而不对其进行硬编码。我尝试将屏幕尺寸除以 2。
它没有居中,什么是正确的方法,请指教。
【问题讨论】:
-
您需要正确设置标签和图像视图的
autoresizingMask。 -
我在一个答案中看到了这个,我不知道如何添加它,你能告诉我吗,标签在图像上方,两者都应该居中
-
尝试设置
logoView.center = view.center;并且删除[logoView autoresizingMask];它是一个吸气剂,你对此无能为力。
标签: ios uitableview uiview cgrectmake