2016-10-06 1 views
1

테이블보기가 있으며 섹션 헤더에 author_img를 표시해야합니다. ViewForSectionHeader 메서드에서 이미지를 원형으로 만들고 싶습니다. 하지만 그렇게했다면 시뮬레이터 나 실제 장치에 관계없이 이미지가 전혀 표시되지 않습니다. 코드를 제거하면 uiimageview에서 이미지를 정상적으로 표시합니다. 내가 이미지를 보여주는 고정 된 크기를 원하기 때문에 uiimageview의 너비와 높이 제한을 설정했습니다. 어떤 아이디어라도주세요?순환 이미지를 사용하는 경우 imageView에 이미지가 표시되지 않습니다.

cell.author_img.layer.cornerRadius = cell.author_img.frame.size.width/2 
    cell.author_img.layer.masksToBounds = true 
    // add a boundary for thumb 
    cell.author_img.layer.borderWidth = 1.5 
    cell.author_img.layer.borderColor = UIColor.whiteColor().CGColor 
+0

사용 cell.author_img.clipsToBounds = 진정한 –

+0

@HimanshuMoradiya 추가,하지만 여전히 저에게 당신의 방법 코드를 표시 및 UI 그게 전부가 – user3162215

+0

작동하지 : 어떤 Xcode의 버전을하다 사용 하시겠습니까? ImageView에 이미지를 할당하는 데 사용되는 코드를 제공하십시오. –

답변

0

그것은 당신이 너무 일찍 CornerRadius를 설정하는, 당신의 author_img의 최종 크기가 아직 해결되지 않는다는 사실에서 올 수 있습니다. 셀의 레이아웃이 완전히 계산되었을 때 cornerRadius를 설정하십시오.

테스트 목적으로이 동작에서 오는지 확인하려면 cornerRadius를 하드 코드 해보십시오. 이미지가 약간 CornerRadius를이있는 경우

cell.author_img.layer.cornerRadius = 10 

는, 그것은 여전히 ​​다른 어떤에서오고, 표시되지 않은 경우 나, 앞에서 설명한 어떤 문제가에서 오는 것을 의미한다.

이미지의 크기가 고정되어 있지 않다면 cornerRadius를 viewDidAppear과 같이 설정하십시오. 가능한 가장 최근의 것을 의미합니다.

+0

20로 cornerRadius를 하드 코딩하고 작동합니다! – user3162215

+0

Ok cool :) 하드 코딩 된 cornerRadius를 사용하면 헤더의 크기가 변경되면 비 둥근 이미지가 생깁니다./반대로 크기를 절반으로 설정하면됩니다. 너비를 동적으로 지정하는 방법은 이미지의 너비이지만 헤더 레이아웃이 더 이상 변경되지 않는 곳에 코드를 넣어야합니다. – RomOne

0
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 

     let headerView : UIView = UIView.init(frame: CGRectMake(0, 0, tableView.frame.size.width, 40)) 
     headerView.backgroundColor = UIColor(red: 75/255.0, green: 193/255.0, blue: 210/255.0, alpha: 1.0) 
     let iconimage: UIImageView = UIImageView(frame: CGRectMake(10, 0, 40, 40)) 
     iconimage.image = UIImage(named: "original.jpg") 
     iconimage.layer.cornerRadius = iconimage.frame.size.height/2 
     iconimage.layer.borderColor = UIColor.whiteColor().CGColor 
     iconimage.layer.borderWidth = 1.0 
     iconimage.clipsToBounds = true 

     let subjectNameLabel = UILabel(frame: CGRect(x: 60, y: 4, width: 250, height: 35)) 
     subjectNameLabel.textAlignment = NSTextAlignment.Center 
     subjectNameLabel.font = UIFont (name: "HelveticaNeue", size: 16) 
     subjectNameLabel.textColor = UIColor.whiteColor() 
     headerView.userInteractionEnabled = true 

     if isFristtime == true { 
      let subjectNameTxtValue = "Mile Ho Tum Humko" 
      subjectNameLabel.text = subjectNameTxtValue 
     }else{ 
      let subjectNameTxtValue = "Saiyaan" 
      subjectNameLabel.text = subjectNameTxtValue 
     } 




     subjectNameLabel.backgroundColor = UIColor(red: 75/255.0, green: 193/255.0, blue: 210/255.0, alpha: 1.0) 
      headerView.addSubview(iconimage) 
     headerView.addSubview(subjectNameLabel) 

     return headerView 
    } 


func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { 
     return 40 
    } 

+0

iconImage의 크기가 고정되어 작동합니다. – user3162215

+0

@ user3162215 이미지 높이를 높이려면 머리말 크기를 늘리고 초기화 시간에 frame.size.hight와 같이 hight를주고 너비는 frame.size.hight로 지정하면 헤더에 큰 이미지가 표시됩니다. –

관련 문제