UITableView 구분선
UITableView의 각 셀 끝에 나타나는 구분선을 어떻게 변경할 수 있습니까? 가는 구분 자형 선 이미지 인 이미지를 갖고 싶습니다.
설정 separatorStyle
에있는 tableview의 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를 추가 한 다음 원점을 셀의 왼쪽 하단 모서리로 설정할 수 있습니다.
이것은 확실히 도움이됩니다. 일. 그러나 속성 검사기에서 구분 기호 "없음"을 설정합니다. cellForRowAtIndexPath 메서드에 다음 코드 작성
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 또는 WillDisplay TableViewDelegates)에이 코드를 넣습니다.
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
XCode 10.2.1에서 스토리 보드를 통해이 작업을 수행하는 방법은 다음과 같습니다. 구분자는 기본적으로 default
라인입니다. none
선을 제거하려면로 설정하십시오 .
구분 기호가없는 기본 옵션, 실선 또는 에칭 된 선을 변경하려는 경우 uitableview의 구분 기호 스타일을 변경하는 두 가지 옵션이 있습니다.
The easiest consist in including a separator line background image to each cell view. You may check then where is located your cell in the tableview to apply the right background image that will give you either a separator line on top of the cell or at the bottom of the cell.
Set the separator style to none in the viewDidLoad of your tableview:
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Set your background image in the (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath function
UIImage* yourBgImg = [[UIImage imageNamed:@"bgImage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
cell.backgroundView = [[UIImageView alloc] initWithImage:yourBgImg];
check the position of your cell in the section with the following:
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPathsection]]; NSInteger row = [indexPath row];
- Add the separator line as a cell. I find a post recently for this here: http://www.dimzzy.com/blog/2012/01/separator-cells-for-uitableview/#disqus_thread
you can try below:
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];
or
- (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;
}
Here is an alternate way to add a custom separator line to a UITableView
by making a CALayer
for the image and using that as the separator line.
// make a CALayer for the image for the separator line
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];
Simplest way to add a separator line under each tableview cell can be done in the storyboard itself. First select the tableview, then in the attribute inspector select the separator line property to be single line. After this, select the separator inset to be custom and update the left inset to be 0 from the left.
참고URL : https://stackoverflow.com/questions/4804632/uitableview-separator-line
'Program Tip' 카테고리의 다른 글
Capybara에서 "_blank"대상이있는 링크의 새 창으로 어떻게 전환합니까? (0) | 2020.10.20 |
---|---|
Visual Studio : 솔루션 탐색기를 현재 파일로 스크롤하는 바로 가기 (0) | 2020.10.20 |
시작하지 못했습니다. (0) | 2020.10.20 |
File.Create 후 파일 닫기 (0) | 2020.10.20 |
Python의 단순 URL GET / POST 함수 (0) | 2020.10.20 |