V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
lcl22hope
V2EX  ›  iDev

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

  •  
  •   lcl22hope · 2015-04-13 21:35:11 +08:00 · 6322 次点击
    这是一个创建于 3320 天前的主题,其中的信息可能已经有所发展或是发生改变。
    补充,已知道设置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?
    请教这种如何解决呢?多谢多谢
    8 条回复    2015-04-14 21:35:37 +08:00
    Galvin
        1
    Galvin  
       2015-04-13 23:49:43 +08:00   ❤️ 1
    我不是很理解你的意思?你的意思是如果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
        2
    qq2511296  
       2015-04-14 10:55:22 +08:00
    @Galvin
    - (CGRect)textRectForBounds:(CGRect)bounds
    - (CGRect)editingRectForBounds:(CGRect)bounds
    这2个是textField的方法吧?
    lcl22hope
        3
    lcl22hope  
    OP
       2015-04-14 11:12:16 +08:00
    @Galvin 和您理解的差不多,当我同时设置了lineFragmentPadding和inset时,原本单行的placeholder就变成两行,嗯 您说的Label的方法我试试,多谢!
    lcl22hope
        4
    lcl22hope  
    OP
       2015-04-14 11:16:46 +08:00
    @qq2511296 嗯 是的 这两个是field里面的方法,请问这个问题,您有什么解决方法么?多谢
    Galvin
        5
    Galvin  
       2015-04-14 15:08:45 +08:00
    @qq2511296 对哦。。记混淆了。。sorry
    lcl22hope
        6
    lcl22hope  
    OP
       2015-04-14 17:22:37 +08:00
    Galvin
        7
    Galvin  
       2015-04-14 20:40:32 +08:00   ❤️ 1
    @lcl22hope 字包围imageview的那个还挺好玩的~
    lcl22hope
        8
    lcl22hope  
    OP
       2015-04-14 21:35:37 +08:00
    @Galvin 效果很帅
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1009 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 20:27 · PVG 04:27 · LAX 13:27 · JFK 16:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.