Reputation: 77
Is it possible to align on the right only a part of the string when displaying in the Table View Cell ?
Here is my sample code :
var arrayAnimals:Array<String> = ["Dogs \(self.arrayData[1])g","Cats \(self.arrayData[2])g","Rabbits \(self.arrayData[3])g","Crocodiles \(self.arrayData[4])g"]
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath)
cell.textLabel!.text = arrayAnimals[indexPath.row]
return cell
}
In that case, is it possible to align left the animal's name and align right its matching data in each cell ?
Thank you in advance !
Upvotes: 0
Views: 22
Reputation: 172
The easiest solution to this problem is to instead use the cell type of value1 (instead of default) which will place a detailTextLabel to the right of the textLabel. You can then set whatever text you’d like to appropriate labels.
To answer your question, though, it is not possible to have two different text alignments in the same line on the same label, to the best of my knowledge.
Upvotes: 1