Я работаю над приложением, где требуется, чтобы заголовок секции был справа, а не по умолчанию.
Я искал, и многие вундеркинды предложили реализовать:
- (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-координату кадра представления заголовка, это не влияет на положение представления. И он всегда находится в центре таблицы.
Мне нужен заголовок справа.