![](/img/trans.png)
[英]How to create a UITextView or a UITextField that has a placeHolder, multiline and vertically centered?
[英]UITextField: Make it higher and position input text vertically centered
一個默認高度UITextField
與邊框樣式UITextBorderStyleRoundedRect
是31px。 對於iPad應用程序,我想制作一個高度為60像素的UITextField,並將文本垂直居中放置以使其看起來很好(默認情況下,文本僅在UITextField的頂部邊框下方幾個像素處繪制)。
如果我做以下......
UITextField *txtLogin = [[UITextField alloc] initWithFrame:CGRectMake(200,200,300,60)];
txtLogin.borderStyle = UITextBorderStyleRoundedRect;
......結果如下: http : //grab.by/6jRc
如您所見,輸入文本不是垂直居中的。 我試圖找到一個解決方案,發現我只需從UITextField繼承我自己的自定義類並覆蓋- (CGRect)textRectForBounds:(CGRect)bounds
方法。 但是,此方法永遠不會被調用,根據此鏈接 ,Apple的API中存在錯誤。 因此,我正在尋找有效的替代方案。
什么是解決此問題並為輸入文本實現正確垂直對齊的好解決方案?
[txtLogin setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.