0

经过大量搜索后,我发布了这个问题,我必须在 UITextfield 的底部放置一个图像,我已经使用以下代码进行了尝试:

letterField.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
letterField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
letterField.textAlignment = UITextAlignmentCenter;
letterField.borderStyle = UITextBorderStyleNone;
UIImageView *myView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"text_line.png"]];
[letterField  setLeftView:myView];
[letterField  setRightViewMode:UITextFieldViewModeAlways];
[myView release];
// letterField.background = [UIImage imageNamed:@"text_line.png"];  
// [letterField setBackground:[UIImage imageNamed:@"text_line.png"]];  
letterField.textColor = [UIColor whiteColor];  
letterField.returnKeyType = UIReturnKeyDone;
4

2 回答 2

0
[yourtextfield insertSubview:imgViewTitleBackGround atIndex:0];// mgViewTitleBackGround is image view with background image.

//或者

[yourtextfield setBackground:[UIImage imageNamed:@"text_line.png"]];// you can add your image
yourtextfield.textColor = [UIColor redColor];

希望,这会帮助你..享受

于 2012-04-26T13:21:16.277 回答
0

对不起,我之前的回答完全错误。从我可以看到您的图像是 text_line.png - 我想它是某种分隔线,我建议您尝试使用 UITextField 的边界创建一个新的 UIView,然后在此视图中添加文本字段并添加UIImage 视图再次作为该视图的子视图正确居中。我不知道这是否符合您的需求,但您可以尝试一下。

于 2012-04-26T13:24:55.480 回答