1

テーブルビューセクションのテキストの位置を変更するにはどうすればよいですか?私はviewForHeaderInSection:Sectionを使用し、そこに次のようなものを作成します。

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
    label.backgroundColor = [UIColor blackColor];
    label.textColor = [UIColor whiteColor];
    label.font = [UIFont fontWithName:@"Gotham-Bold" size:17.0f];

    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.comlpetedFetchedResultsController sections] objectAtIndex:section];
    label.text = [@" " stringByAppendingString:[sectionInfo name]];
    return label;
}

UILabelフレームのパラメーターのサイズは関係ありません。常に同じ結果が得られます。

ここに画像の説明を入力してください

UILabelのテキストを垂直方向に中央揃えするにはどうすればよいですか?ありがとう

4

3 に答える 3

4

試す

[yourLabel setNumberOfLines:0];
[yourLabel sizeToFit];
[yourLabel setContentMode:UIViewContentModeCenter];
于 2013-01-23T15:44:17.730 に答える
3

ラベルをUIViewに配置してから、ビューを返します。

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 30)];
[view addSubview:label];
return view;

次のメソッドを実装していることを確認してください。

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

それ以外の場合、ビューは単にセルの上に表示されます。

于 2013-01-23T15:56:07.097 に答える
2

このリンクを通過します:NSTextAlignment

また、以下に示すコードスニペットが役立つ場合があります

  UILabel *myLabel = [[UILabel alloc] init];

  [myLabel setText:@"Abc"];
  [myLabel setTextAlignment:NSTextAlignmentCenter];
于 2013-01-23T15:43:46.493 に答える