是否可以在iOS中以编程方式在图像内添加标签?

时间:2018-10-03 08:55:39

标签: ios

enter image description here

我需要设置图像中 88:88 所在的时间。 欢迎任何建议。

1 个答案:

答案 0 :(得分:0)

您需要在UIImageView内显示图像(无文本),并添加UILabel作为子视图。

let image = UIImageView()
image.frame = CGRect(x: 0, y: 0, width: 50, height: 50)

let label = UILabel()
label.text = "88:88"
image.addSubview(label)
label.frame = image.frame
label.textAlignment = .center

注意:将标签设置为与图像视图相同的框架,并使文本对齐居中,确保标签在图像内部居中(垂直和水平)。