user15688965
user15688965

Reputation:

How does one align text to the top, center part in a UITableViewCell (In Swift 5)?

I understand this code can align the text of a UITableViewCell to the center:

cell.textLabel?.textAlignment = .center

However, I need to align it to the top of the same cell, and also center it. How can I achieve this? UIEdgeContentInsets? Bit confused and I need help. Thanks!

Example, would be something like;

cell.textLabel?.textAlignment = .topCenter

Note; previous line doesn't actually exist as a way to place it in the top center of the cell. But, I am thinking there has to be a way apple provides to do this.

I've read through docs can't find anything -_-. Does anyone have any custom solutions?

Upvotes: 0

Views: 811

Answers (2)

matt
matt

Reputation: 535945

Labels do not do vertical alignment; they are vertically centered only. If you don't like that, move the label, or allow its height to fit its contents, or don't use a label.

Upvotes: 1

Riajur Rahman
Riajur Rahman

Reputation: 2034

You could create a Custom TableView Cell & use it:

enter image description here

Upvotes: 0

Related Questions