2013-02-01 51 views
0

我正在開發一個應用程序,我需要爲大文本放置UITextView。我有一個大小爲180X89的背景圖像(與UITextView框架大小相同)。將圖像放在UITextView後面時,一切都顯得很好,但是當用戶點擊文本區域並出現鍵盤時,光標就會出現在圖像邊緣的外部。UITextView背景圖像不適合UITextView幀的幀大小

我希望光標出現在文本框中。請幫忙。

代碼獲得的UITextView

CGRect textViewFrame = CGRectMake(125.0f, 155.0f, 180.0f, 90.0f); 
UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame]; 
textView.returnKeyType = UIReturnKeyDone; 
textView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: @"textbox.png"]]; 
textView.delegate = self; 
[self.view addSubview:textView]; 

image of textbox which I am using for background Screen shots showing cursor on left corner outside the background image

+0

改爲將其設置爲背景圖像嘗試將textView放置在imageview中iamgeView.image = backgroundImage –

回答

0

有非常簡單的方法。只需在TextView後面使用UIImageView並將UITextView背景顏色設置爲清晰的顏色即可。

0

,你可以在這樣的情況下,做的是使UITextView的尺寸有點小,所以它只是進來烏爾背景圖片以及使用該框架<QuartzCore>textview.layer.cornerRadius = 10;(進口頭用於給UITextView圓角半徑框架)。這種方法也會使UITextView邊緣有點圓,使它看起來像上面提供的圖像。

因此,簡而言之,添加UIImageView,然後在其上面添加UITextView,並將textview的背景設置爲clearcolor。希望這可以幫助 !!! :)

0

添加的UIImageView你的觀點,然後在用的UIImageView的

CGPointMake(10,10) as Origin 

和TextView中的CGSizeMake(imageView.frame.size.width - 20.0, imageView.frame.size.hieght - 20.0) as Size內框添加UITextView的。

+0

我該怎麼做?請讓我知道這樣做的代碼。 現在我可以將光標放置在文本框中,但字母仍然被裁剪。 我放置了UIImageView,並在其上放置了UiTextView,並製作了 textView.layer.cornerradious = 50; – Saty

+0

編輯@glyytchy答案。覈實。 – 2013-02-01 07:10:52

1

試試這個:

UIImage  *bgImage  = [UIImage imageNamed:@"textbox.png"]; 
UIImageView *bgImageView = [[UIImageView alloc] initWithImage:bgImage]; 

CGRect textViewFrame = CGRectMake(125.0f, 155.0f, 180.0f, 90.0f); 
bgImageView.frame = textViewFrame; 

UITextView *textView = [[UITextView alloc] initWithFrame:textViewFrame]; 

textView.returnKeyType = UIReturnKeyDone; 
textView.delegate  = self; 

[self.view addSubview:bgImageView]; 
[self.view addSubview:textView]; 

或者類似的東西。