请教 UITextView 内容缩进问题?需求是不想让 content 紧挨着 TextView 的边界,即左右都有微量偏移,且一行显示 placeholder 不会因为设置了 textContainer 而两行显示。

2015-04-13 21:35:11 +08:00
 lcl22hope
补充,已知道设置textContainer.lineFragmentPadding=0可以将默认的padding置为0,并且通过设置textContainerInset属性可以实现content的上下左右偏移,但是当两个同时存在时,placeholder的单行显示就被破坏了,eg:
//单独设置textContainer.lineFragmentPadding 时
_contentView.textContainer.lineFragmentPadding = 0;
// -----what's on your mind? //placeholder单行显示
// 同时设置后
_contentView.textContainer.lineFragmentPadding = 0;
_contentView.textContainerInset = UIEdgeInsetsMake(5, 5, 5, 0);
// ----what‘s on your
// ----mind?
请教这种如何解决呢?多谢多谢
6338 次点击
所在节点    iDev
8 条回复
Galvin
2015-04-13 23:49:43 +08:00
我不是很理解你的意思?你的意思是如果placeholder的缩进跟着content的话就会变成两行显示?要让placeholder紧挨着textview的边界吗?
uitextview的缩进我是通过给uitextview定义一个inset的property,当每次set的时候,调用[self layoutIfNeed],在自己的uitextview中重写
- (CGRect)textRectForBounds:(CGRect)bounds
- (CGRect)editingRectForBounds:(CGRect)bounds
这两个方法来实现缩进的。。
我之前弄uitextview的时候设置placeholder是通过判断textview.text来实现的,但是后面觉得这种方式有挺大的局限性的。。所以我就在uitextview上加了个label的property,这样能满足我的很多要求。希望能帮到你:-)
qq2511296
2015-04-14 10:55:22 +08:00
@Galvin
- (CGRect)textRectForBounds:(CGRect)bounds
- (CGRect)editingRectForBounds:(CGRect)bounds
这2个是textField的方法吧?
lcl22hope
2015-04-14 11:12:16 +08:00
@Galvin 和您理解的差不多,当我同时设置了lineFragmentPadding和inset时,原本单行的placeholder就变成两行,嗯 您说的Label的方法我试试,多谢!
lcl22hope
2015-04-14 11:16:46 +08:00
@qq2511296 嗯 是的 这两个是field里面的方法,请问这个问题,您有什么解决方法么?多谢
Galvin
2015-04-14 15:08:45 +08:00
@qq2511296 对哦。。记混淆了。。sorry
lcl22hope
2015-04-14 17:22:37 +08:00
Galvin
2015-04-14 20:40:32 +08:00
@lcl22hope 字包围imageview的那个还挺好玩的~
lcl22hope
2015-04-14 21:35:37 +08:00
@Galvin 效果很帅

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/183502

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX