【发布时间】:2015-05-08 15:33:41
【问题描述】:
我有一个 UIImageView 作为我的表格视图的背景视图。当表格没有数据时,我将添加一个 UILabel 作为图像视图的子视图。我无法让标签居中。标签总是偏右。
UIImageView *backgroundImageView = [[UIImageView alloc]initWithFrame:self.tableView.frame];
backgroundImageView.image = [UIImage imageNamed:@"background"];
backgroundImageView.center = self.tableView.center;
self.noLocationsLabel = [[UILabel alloc]initWithFrame:backgroundImageView.frame];
self.noLocationsLabel.center = backgroundImageView.center;
self.noLocationsLabel.text = @"No saved locations";
self.noLocationsLabel.textAlignment = NSTextAlignmentCenter;
self.noLocationsLabel.textColor = [UIColor blackColor];
self.noLocationsLabel.font = [UIFont fontWithName:@"Chalkboard SE" size:24.0];
self.tableView.backgroundView = backgroundImageView;
if (self.locationsArray.count == 0) {
self.navigationItem.rightBarButtonItem.enabled = NO;
[self.tableView.backgroundView addSubview:self.noLocationsLabel];
self.tableView.userInteractionEnabled = NO;
}
【问题讨论】:
-
为什么要将图像视图框架给 uilabel 框架?
标签: ios objective-c uiimageview uilabel addsubview