3

テキストフィールドにテキストをより具体的に配置したいと思います。

私の現在のコード:

UITextField * textFieldIndustry = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 465, 68)];
textFieldIndustry.font = [UIFont systemFontOfSize:17.0];  
textFieldIndustry.placeholder = @"Tap to..";  
textFieldIndustry.textAlignment = NSTextAlignmentCenter;

このコード:

textFieldIndustry.textAlignment = NSTextAlignmentCenter; 

テキストを中央に配置しますが、必要な場所に正確には配置しません。たとえば、X & Y を使用して配置するにはどうすればよいですか?

4

5 に答える 5

2

サブクラス化せずに UITextField で暗黙的にテキストの位置を設定することはできません。

代わりに UITextView を使用でき、同じアプローチを使用する必要があります。

UITextView *textView;
UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
[textView setContentInset:insets];

このアプローチは、UITextField のサブクラス化でも使用できます。

于 2013-05-08T14:18:17.870 に答える
0

「UIEdgeInsets」を使用して、必要な方向にテキストフィールドのパディングを行うだけです。

例: UIEdgeInsets insets = UIEdgeInsetsMake(0, 10, 0, 0); [textView setContentInset:インセット]; ..... から 10 ピクセル後にテキストフィールドが表示されます。このように指定できます。

幸せなコーディング...

于 2013-12-19T13:53:32.300 に答える
0
UITextField *textFieldNote = [[UITextField alloc] initWithFrame:CGRectMake(5, 5, 310, 110)];
textFieldNote.placeholder = @"Ghi chú";
textFieldNote.textAlignment = NSTextAlignmentLeft;
textFieldNote.contentVerticalAlignment = UIControlContentVerticalAlignmentTop;
于 2014-04-09T09:47:17.130 に答える