Search code examples
swiftuitableviewfontsuifontcustom-cell

When i try to apply "Font" to one tableview cell it automatically apply to other cells when scroll tableview


I have a custom tableview.

I need to set Bold Italic (Helvetica-BoldOblique) font to only cell.But when it scroll the tableview it also apply to other cells one by one.How to solve this?

    func applyFontToTableviewCell() {

    var couIn = NSIndexPath(forRow: 2, inSection: 0)
    var couCell = colorTableView.cellForRowAtIndexPath(couIn)
    couCell?.textLabel?.font = UIFont(name: "Helvetica-BoldOblique", size: 18.0)


    }

I tried this same code in cellForRowAtIndexPath also.But the same issue occured.

Thanks in Advance.


Solution

  • You can applied bold font on alternative cell like as bellowed way.

     func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
                let couCell = tableView.dequeueReusableCellWithIdentifier(textCellIdentifier, forIndexPath: indexPath) as UITableViewCell
    
                let row = indexPath.row
    
                if row == 2 || row == 4 || row == 6 {
                  couCell?.textLabel?.font = UIFont(name: "Helvetica-BoldOblique", size: 18.0)
               }
              else{
                   couCell?.textLabel?.font = UIFont(name: "Helvetica", size: 18.0)
               }
    
                return cell
            }
    

    Hope this help you.