UI 테이블 보기 섹션 사이의 공간 줄이기
UITableView의 두 섹션 사이의 공간을 줄일 수 있는 방법이 있습니까?제가 가지고 있는 모든 부분 사이에는 약 15개의 픽셀이 있습니다.이미 0을 반환하려고 했습니다.-tableView:heightForFooterInSection:
그리고.-tableView:heightForHeaderInSection:
하지만 그것은 아무것도 변하지 않습니다.
좋은 의견이라도 있나?
조금 까다롭긴 했지만 다음 코드를 사용해 보십시오.
- (CGFloat)tableView:(UITableView*)tableView
heightForHeaderInSection:(NSInteger)section {
if (section == 0) {
return 6.0;
}
return 1.0;
}
- (CGFloat)tableView:(UITableView*)tableView
heightForFooterInSection:(NSInteger)section {
return 5.0;
}
- (UIView*)tableView:(UITableView*)tableView
viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
- (UIView*)tableView:(UITableView*)tableView
viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectZero];
}
그에 따라 값을 변경합니다.공간을 제거하기 위해 0.0은 허용되지 않을 것 같습니다.가장 작은 제정신 값은 1.0인 것 같습니다.
거리를 0으로 줄이려면 다음을 사용해야 합니다.
tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;
UITableViewDelegate를 제공하면 0보다 큰 부동 소수점에서만 효과가 발생하기 때문입니다.
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
return 1.0;
}
-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 1.0;
}
-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}
-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
return [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
}
(iOS 4.1을 XCode 4.0.2와 함께 사용)
실제로 크기 탭 아래의 인터페이스 작성기에서 바닥글/머리글/셀 높이를 설정할 수 있습니다.기본적으로 머리글/바닥글은 10.0으로 설정됩니다.
단면 머리글/바닥글 높이를 줄여야 합니다.그러면 구간 사이의 공간이 줄어들 것입니다.
이 코드를 사용해 보세요.
저한테는 효과가 있어요 :-)
tableView.sectionHeaderHeight = 2.0;
tableView.sectionFooterHeight = 2.0;
또한 스토리보드에서 섹션 바닥글과 머리글의 높이를 줄일 수 있습니다.표 보기 -> size inspector.횡단 높이로 이동합니다.
기본적으로 일반 스타일 테이블의 경우 22로 설정되고 그룹화된 스타일 테이블의 경우 10으로 설정됩니다.머리글과 바닥글의 값을 개별적으로 늘리거나 줄여 값을 구성할 수 있습니다.
저에게 문제는 그룹화된 테이블 뷰 스타일을 사용했기 때문입니다.UITableViewStyleGrouped
. 평이한 스타일로 바꿨을 때 (UITableViewStylePlain
) 나의tableView:heightForHeaderInSection:
각 섹션 헤더의 크기를 결정하는 것은 메소드뿐이었습니다.
이를 사용하면 0이 예상대로 작동하지 않을 수 있습니다.
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return .leastNormalMagnitude
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return .leastNormalMagnitude
}
iOS7용 업데이트: 아크 자동 릴리스 업데이트로 인해, 여기 @Martin Stolz 코드가 편집되었습니다.
-(CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 6;
return 1.0;
}
-(CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section
{
return 5.0;
}
-(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
-(UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
(iOS7, Xcode v5.0 사용)
저는 단지 다음 코드를 사용하는 것만으로 이 문제가 해결되었습니다.
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return section == 0 ? 1 : 20 // 20 is my other sections height
}
첫 번째 섹션에 대해 1을 반환하면 문제가 해결되었습니다.
머리글/바닥글 공간을 변경하려면 다음 방법을 구현해야 합니다.
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?
그리고.
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat
(해당 방법을 사용하여 바닥글 높이 변경)
다음 코드는 섹션 주위의 공백을 완전히 제거합니다.
public func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return nil
}
public func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return nil
}
public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return .leastNonzeroMagnitude
}
public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return .leastNonzeroMagnitude
}
스위프트 5, iOS 13+
옵션 1 - 표 보기를 작성할 때
tableView.sectionHeaderHeight = 0
tableView.sectionFooterHeight = 0
옵션 2 - 다른 뷰 및 섹션에 대해 유연성 향상
// Top space for sections
public func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 0
}
// Bottom space for sections
public func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0
}
언급URL : https://stackoverflow.com/questions/2817308/reducing-the-space-between-sections-of-the-uitableview
'programing' 카테고리의 다른 글
테스트 사용자에 대한 iOS 앱 내 구매 샌드박스에서 구매 지우기 (0) | 2023.06.05 |
---|---|
Xcode 9 문제 수정: "iPhone 사용 중: iPhone에 대한 디버거 지원 준비 중" (0) | 2023.06.05 |
ggplot에서 모든 x축 레이블 제거 (0) | 2023.06.05 |
데이터베이스 테이블의 모든 레코드 삭제 (0) | 2023.06.05 |
루비 배열에서 문자열로 변환 (0) | 2023.06.05 |