要将 UITextField 的文字向左偏移,可以使用 UITextField 的 leftView 属性来添加一个空的 UIView 作为左边的偏移视图。

例如,以下代码将 UITextField 的文字向左偏移 10 个点:

let textField = UITextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30))
textField.borderStyle = .roundedRect

let leftView = UIView(frame: CGRect(x: 0, y: 0, width: 10, height: 30))
textField.leftView = leftView
textField.leftViewMode = .always

这将使 UITextField 的文字在视图中向左偏移 10 个点。你可以根据需要调整 leftView 的宽度来调整偏移量。

iOS UITextField 文字向左偏移 - 详细教程

原文地址: https://www.cveoy.top/t/topic/oSWn 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录