[iphone] 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를 추가 한 다음 원점을 셀의 왼쪽 하단 모서리로 설정할 수 있습니다.