UI 테이블 뷰 구분선
UI 테이블 보기에서 각 셀 끝에 나타나는 구분선을 변경하려면 어떻게 해야 합니까?나는 얇은 분리기 타입의 라인 이미지를 원합니다.
설정separatorStyle…의 탁상풍경.UITableViewCellSeparatorStyleNone구분자 이미지를 각 셀에 하위 보기로 추가하고 프레임을 올바르게 설정합니다.
사용해 보세요.
목표 C
[TableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
[TableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"Divider_line@2x.png"]]];
스위프트
tableView.separatorStyle = UITableViewCellSeparatorStyle.SingleLine
tableView.separatorColor = UIColor(patternImage: UIImage(named: "YOUR_IMAGE_NAME")!)
먼저 코드를 작성할 수 있습니다.
{ [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];}
그 후
{ #define cellHeight 80 // You can change according to your req.<br>
#define cellWidth 320 // You can change according to your req.<br>
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seprater_line.png"]];
imgView.frame = CGRectMake(0, cellHeight, cellWidth, 1);
[customCell.contentView addSubview:imgView];
return customCell;
}
}
이미지에 따라 패턴을 지정할 구분 기호의 색상을 설정합니다.
에viewDidLoad:
self.tableView.separatorColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mySeparatorImage"]];
제 프로젝트는 iOS 7을 기반으로 합니다. 이것은 제게 도움이 됩니다.
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
그런 다음 하위 뷰를 구분 기호로 셀에 넣습니다!
사용해 보십시오.
UIImageView *separator = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"separator.png"]];
[cell.contentView addSubview: separator];
이것은 제가 어떻게 그것을 꽤 잘 작동시켰는지 보여주는 예입니다.
표 보기에 대한 구분 기호 스타일을 없음으로 설정해야 합니다.
예를 들어 셀 프레임의 높이와 너비가 1포인트인 UIImageView를 추가한 다음 셀의 왼쪽 하단 모서리에 원점을 설정할 수 있습니다.
XCode 10.2.1의 스토리보드를 통해 이 작업을 수행하는 방법은 다음과 같습니다.구분 기호 기본값:default그것이 선입니다.으로 설정none라인을 제거합니다.
이것은 확실히 도움이 됩니다.작동 중이지만 특성 검사기에서 구분 기호를 "없음"으로 설정합니다.cellForRowAt에 다음 코드 기록IndexPath 메서드
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0,
cell.contentView.frame.size.height - 1.0,
cell.contentView.frame.size.width, 1)];
lineView.backgroundColor = [UIColor blackColor];
[cell.contentView addSubview:lineView];
스위프트 3/4
사용자 지정 구분선에서 이 코드를 UITableViewCell의 하위 클래스인 사용자 지정 셀(또는 사용자 지정이 아닌 셀의 경우 CellForRow 또는 WillDisplayTableViewDelgates)에 넣습니다.
let separatorLine = UIView.init(frame: CGRect(x: 8, y: 64, width: cell.frame.width - 16, height: 2))
separatorLine.backgroundColor = .blue
addSubview(separatorLine)
viewDidLoad 메서드:
tableView.separatorStyle = .none
구분 기호가 없는 기본 옵션, 실선 또는 식각된 선을 변경하려는 경우 적합한 뷰의 구분 기호 스타일을 변경할 수 있는 두 가지 옵션이 있습니다.
가장 쉬운 방법은 각 셀 보기에 구분선 배경 이미지를 포함하는 것입니다.그런 다음 표 보기에서 셀의 위치를 확인하여 셀 상단 또는 셀 하단에 구분선을 제공하는 올바른 배경 이미지를 적용할 수 있습니다.
테이블 뷰의 뷰DidLoad에서 구분 기호 스타일을 none으로 설정합니다.
[self.tableSetSeparatorStyle:UITableViewCellSeparatorStyleNone];
(UITableViewCell *) 테이블 보기에서 배경 이미지를 설정합니다. (UITableView *) 테이블 보기CellForRowAtIndexPath:(NSIndexPath *)indexPath 함수
UIImage* yourBgImg = [[UIImage imageNamed:@"bgImage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];cell.backgroundView = [UIImageView alloc] inImageWithImage:yourBgImg];
다음을 사용하여 섹션의 셀 위치를 확인합니다.
NSInteger 섹션 행 = [tableViewNumberOfRowsInsection:[indexPath섹션]; NSInteger 행 = [indexPath 행];
- 구분선을 셀로 추가합니다.최근에 이에 대한 게시물을 찾았습니다. http://www.dimzzy.com/blog/2012/01/separator-cells-for-uitableview/ #disqus_bullets
아래에서 시도할 수 있습니다.
UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];
separator.backgroundColor = myColor;
[cell.contentView addSubview:separator];
또는
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"separator.png"]];
imageView.frame = CGRectMake(0, 100, 320, 1);
[customCell.contentView addSubview:imageView];
return customCell;
}
은 사용자 지정 구분선에 입니다.UITableView▁a▁.CALayer이미지를 구분선으로 사용합니다.
구분선에 대한 이미지의 CAL 레이어 만들기
CALayer *separator = [CALayer layer];
separator.contents = (id)[UIImage imageNamed:@"myImage.png"].CGImage;
separator.frame = CGRectMake(0, 54, self.view.frame.size.width, 2);
[cell.layer addSublayer:separator];
각 테이블 뷰 셀 아래에 구분선을 추가하는 가장 간단한 방법은 스토리보드 자체에서 수행할 수 있습니다.먼저 테이블 뷰를 선택한 다음 속성 관리자에서 단일 선이 될 구분선 특성을 선택합니다.그런 다음 사용자 지정할 구분자 삽입을 선택하고 왼쪽 삽입을 왼쪽에서 0으로 업데이트합니다.
언급URL : https://stackoverflow.com/questions/4804632/uitableview-separator-line
'programing' 카테고리의 다른 글
| ora_hash는 결정론적입니까? (0) | 2023.08.27 |
|---|---|
| 수행 표시줄의 뒤로 단추를 사용자 지정하는 방법 (0) | 2023.08.22 |
| 아이폰 및 OpenCV (0) | 2023.08.22 |
| node.js에서 다중 줄 문자열을 수행하려면 어떻게 해야 합니까? (0) | 2023.08.22 |
| 순수 Java에서 스프링 기본 설정을 재정의하지 않고 스프링 부팅 애플리케이션에서 Jackson을 구성하는 방법 (0) | 2023.08.22 |
