>

테이블 뷰 섹션에 구분선을 추가하고 싶었습니다. 현재 헤더 섹션보기의 코드는 다음과 같습니다.

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
    // recast your view as a UITableViewHeaderFooterView
    UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
    header.backgroundView.backgroundColor = [UIColor clearColor];
    header.textLabel.textColor = [UIColor blackColor];
    [header.textLabel setFont:[UIFont fontWithName:@"Rubik-Regular" size:15.0]];
}

  • 답변 # 1

    있는 경우

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
    
    

    그것을 만드는 것이 더 좋을 것입니다 :

    - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
        // recast your view as a UITableViewHeaderFooterView
        UITableViewHeaderFooterView *header = // make header here
        header.backgroundView.backgroundColor = [UIColor clearColor];
        header.textLabel.textColor = [UIColor blackColor];
        [header.textLabel setFont:[UIFont fontWithName:@"Rubik-Regular" size:15.0]];
        // make a view with height = 1 attached to header bottom
        UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(0, header.frame.size.height, header.frame.size.width, 1)];
        [separator setBackgroundColor:[UIColor yellowColor]];
        [header addSubview:separator];
        return header;
    }
    
    

  • 답변 # 2

    Swift 4

    override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let footerView = UIView()
        let separatorView = UIView(frame: CGRect(x: tableView.separatorInset.left, y: footerView.frame.height, width: tableView.frame.width - tableView.separatorInset.right - tableView.separatorInset.left, height: 1))
        separatorView.backgroundColor = UIColor.separatorColor
        footerView.addSubview(separatorView)
        return footerView
    }
    extension UIColor {
       class var separatorColor: UIColor {
         return UIColor(red: 244.0/255.0, green: 244.0/255.0, blue: 244.0/255.0, alpha: 1.0)
       }
    }
    
    

  • 답변 # 3

    다음과 같이 할 수 있습니다 :

    CGRect sepFrame = CGRectMake(0, view.frame.size.height-1, 320, 1); 
    UIView *separatorView =[[UIView alloc] initWithFrame:sepFrame]; 
    seperatorView.backgroundColor = UIColor.yellow()
    [header addSubview:separatorView];
    
    

관련 자료

  • 이전 Javascript에서 PHP로 데이터를 보내는 방법
  • 다음 oracle - SYSAUD $에 audit_trial 저장