ViewController에 이미지 및 레이블이있는 Headerview를 표시하려면
-
20-09-2019 - |
문제
저는 iPhone 개발을 처음 사용합니다. 하나의 뷰 컨트롤러를 만들었고 그룹화 된 테이블보기를 사용했습니다. 이제 이미지와 레이블로 내 ViewController의 헤더보기를 표시하고 싶습니다. 저를 인도 하고이 문제를 도와주세요.
감사.
해결책
Headerview 또는 SectionHeaderView를 의미합니까? Headerview에 하위 뷰를 추가 할 수 있습니다 viewDidLoad
방법:
- (void)viewDidLoad {
[super viewDidLoad];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 225)];
label.text = @"BlaBla";
[self.tableHeaderView addSubview:label];
}
라벨의 크기와 위치를 initWithFrame
메소드 및 TableHeaderView에 하위 뷰로 레이블을 추가하십시오. 여러 레이블 로이 작업을 수행 할 수 있습니다.
섹션 헤드를 의미하는 경우 tableView:viewForHeaderInSection:
새로운보기를 만들고 다른 서브 뷰를 추가 해야하는 방법 :
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 40)];
label.text = @"BlaBla";
[view addSubview:label];
[label release];
return [view autorelease];
}
이 경우 메소드도 구현해야합니다. tableView:heightForHeaderInSection:
위의 방법에서 생성 한 뷰의 높이를 반환해야합니다.
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 50.0f;
}
제휴하지 않습니다 StackOverflow