Paste text in UILabel on the left

I have a UILabel that I use to display multiple lines of text. The moment the text is displayed, it is directly opposite the left side of the label, which does not look too large. I would like the text to be slightly pasted to the left.

This is my code:

if notes.objectAtIndex(indexPath.row) as NSString == "" { cell.notesLabel.text = "No notes to display." cell.notesLabel.textAlignment = NSTextAlignment.Center } else { cell.notesLabel.textAlignment = NSTextAlignment.Left } 

I watched a few examples of Objective-C, but I couldn't get them to work, and I really don't think they were what I was looking for.

In addition, I tried to do the same with a different label, in which case I suggested that I could just add "" to the end of the line (since this is one line label) to move it from the right, but I was surprised seeing that this does not work?

Thanks.

+5
source share
1 answer

To insert text from the left, you must subclass UILabel and override drawTextInRect :,

 class RDLabel: UILabel { override func drawTextInRect(rect: CGRect) { let newRect = CGRectOffset(rect, 10, 0) // move text 10 points to the right super.drawTextInRect(newRect) } } 
+11
source

Source: https://habr.com/ru/post/1204526/


All Articles