Image not showing in imageView if I used circular image

后端 未结 2 456
再見小時候
再見小時候 2021-01-27 00:33

I have a table view and I need to show author_img in section header. In ViewForSectionHeader method, I want to make the image to be circular. But If I did that, the images are n

2条回答
  •  日久生厌
    2021-01-27 01:34

    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
        }
    

提交回复
热议问题