2011-01-27 38 views

Trả lời

13
CGFloat width = [aTextField.text sizeWithFont:aTextField.font].width; 
+0

hoạt động hoàn hảo, thx – gabac

6

Nếu bạn đang tìm kiếm nhân vật đếm nó là thế này

int textLength = [someTextField.text length] 

Nếu bạn đang tìm kiếm pixel chiều rộng cố

này
CGSize size = [someTextField.text sizeWithFont:someTextField.font]; 
//size.width contains the width 
0

TextField là đại biểu đó là attac trong xây dựng giao diện hơn ......

[textField.text dài]

2

Trong Swift 3.0

let size:CGSize = aTextField.attributedText.size() 
let height = size.height 
let width = size.width 
Các vấn đề liên quan