3

UITextFields の背景として配置しようとしているサイズ 360X44 の背景画像がありますが、予期しない動作を示しています。画像が始まる前にカーソルが表示されますが、書き込み場所にテキストが書き込まれます。

背景のイメージ

私の UiTextField の実装

UITextField *textFieldRounded = [[UITextField alloc] initWithFrame:CGRectMake(100, 75, 215, 30)];
textFieldRounded.borderStyle = UITextBorderStyleNone;
UIImage *fieldBGImage = [[UIImage imageNamed:@"textfield_normal.png"]  stretchableImageWithLeftCapWidth:50 topCapHeight:50];
[textFieldRounded setBackground:fieldBGImage];
textFieldRounded.textColor = [UIColor blackColor];
textFieldRounded.font = [UIFont systemFontOfSize:17.0];
textFieldRounded.placeholder = @"http://";  //place holder
textFieldRounded.backgroundColor = [UIColor whiteColor];
textFieldRounded.autocorrectionType = UITextAutocorrectionTypeNo;
textFieldRounded.backgroundColor = [UIColor clearColor];
textFieldRounded.keyboardType = UIKeyboardTypeDefault;
textFieldRounded.returnKeyType = UIReturnKeyDone;
textFieldRounded.clearsOnBeginEditing = NO;
textFieldRounded.clearButtonMode = UITextFieldViewModeWhileEditing;    
[self.view addSubview:textFieldRounded];    
textFieldRounded.delegate = self;
4

3 に答える 3

4

次のコードのようにTextFiledの背景画像を設定しました。

        [YourTextFiled setFont:[UIFont systemFontOfSize:18]];
        YourTextFiled.textAlignment = UITextAlignmentLeft;
        YourTextFiled.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
        YourTextFiled.leftViewMode = UITextFieldViewModeAlways;
        YourTextFiled.background = [[UIImage imageNamed:@"xFOEr.png"] stretchableImageWithLeftCapWidth:7 topCapHeight:17];

以下のように見えます"-

ここに画像の説明を入力してください

于 2013-01-31T05:38:22.450 に答える
0

背景色として画像を追加する代わりに、私は提案したいと思います。別のコンポーネントとして追加します。つまり、最初にを追加してUIImageViewから、にを追加UITextFieldします。

それまでの間、現在のコードでこの変更を行ってみてください。

UITextField *textFieldRounded = [[UITextField alloc] initWithFrame:CGRectMake(100, 75, 360, 44)];
于 2013-01-31T05:31:41.487 に答える
0
UITextView *textView = [[UITextView alloc]initWithFrame: window.frame];
textView.text = @"text\n text\n text";
UIImageView *imgView = [[UIImageView alloc]initWithFrame: textView.frame];
imgView.image = [UIImage imageNamed: @"myImage.jpg"];
[textView addSubview: imgView];
[textView sendSubviewToBack: imgView];
[window addSubview: textView];

background プロパティを使用しないでください。画像をサブビューとして追加し、サブビューを背面に送信します。

于 2013-01-31T09:01:16.840 に答える