Laurenswuyts
Laurenswuyts

Reputation: 2142

Center label into imageview (Swift)

I have a tableview with a tablecell and ito that cell I have an imageview. Whenever I have an imageurl I will show the image into that imageview but when there is no imageurl I want to give the imageview a color and show a letter into it.

Basically like what's happening in the gmail app.

example of what i want

But I can't seem to center the label into that imageview as I can only center it vertically and horizontally in the cell itself in my storyboard.

Upvotes: 0

Views: 1101

Answers (1)

IxPaka
IxPaka

Reputation: 2008

You can just create your own label on top of imageview(same size, same origin), set your text to that label and center text in it.

myLabel.text = "D"
myLabel.textAlignment = NSTextAlignment.Center;

Upvotes: 1

Related Questions