我正在开发一个应用程序,它要求部分的标题应该在右边而不是默认的左边。
我搜索并且许多极客建议实施:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
static UIView *headerView;
if (headerView != nil)
return headerView;
NSString *headerText = NSLocalizedString(@"البحث الأخيرة", nil);
// set the container width to a known value so that we can center a label in it
// it will get resized by the tableview since we set autoresizeflags
float headerWidth = 150.0f;
float padding = 10.0f; // an arbitrary amount to center the label in the container
headerView = [[UIView alloc] initWithFrame:CGRectMake(300, 0.0f, headerWidth, 44.0f)];
headerView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// create the label centered in the container, then set the appropriate autoresize mask
UILabel *headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(padding, 0, headerWidth - 2.0f * padding, 44.0f)];
headerLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
headerLabel.textAlignment = UITextAlignmentRight;
headerLabel.text = headerText;
[headerView addSubview:headerLabel];
return headerView;
}
但是,当我尝试增加标题视图框架的 x 坐标时,它不会影响视图的位置。它始终位于表格视图的中心。
我需要标题在右边。