Emre Duman Emre Duman - 28 days ago 5
iOS Question

Unicode non-breaking space is removed end of label

I'm using tableview and i use one cell to create many columns.My column number is not fixed so i had to create columns using for loop inside cellForRowAt function.I want to give some spaces between my labels inside my cell.This piece of code succesfully inserts non-breaking spaces to head of the label but it removes end of the label.Thanks for your help.

let spaces = String(repeating:"\u{00A0}",count : columnSpaceCount)
if globalSubviewHeaderStructArray[i].type == "numeric"{
if globalSubviewHeaderStructArray[i].digitsAfterComma != "0" {
var dataNumber = applyComma(comma : globalSubviewHeaderStructArray[i].digitsAfterComma , data : globalSubviewDataArray[indexPath.row][i])
var newString = "\(spaces)\(checkCurrency(option: globalSubviewHeaderStructArray[i].currency, data: dataNumber))\(spaces)"
newLabel.text = newString
}else{
var newString = "\(spaces)\(checkCurrency(option: globalSubviewHeaderStructArray[i].currency, data: globalSubviewDataArray[indexPath.row][i]))\(spaces)"
newLabel.text = newString
}
}else{
var newString = "\(spaces)\(checkCurrency(option: globalSubviewHeaderStructArray[i].currency, data: globalSubviewDataArray[indexPath.row][i]))\(spaces)"
newLabel.lineBreakMode = .byTruncatingMiddle
newLabel.text = newString
}

Answer

I want to give some spaces between my labels inside my cell

Don't do this by messing with the content of the label. Do it by messing with the position / size of the labels themselves. Insert actual space (that is, empty pixels) between the labels.

Comments