【问题标题】:What are the default values for caretRectForPosition or How to set a BOOL that determines an override of a classcaretRectForPosition 的默认值是什么或如何设置确定类覆盖的 BOOL
【发布时间】:2013-10-17 10:10:31
【问题描述】:

在我的 UITextField 子类中,我使用下一个代码来隐藏闪烁的插入符号:

- (CGRect)caretRectForPosition:(UITextPosition *)position
{
    return CGRectZero;
}

我的目标是设置一个属性来启用或禁用上述功能。我的问题是我不知道为了显示插入符号而默认的矩形是什么。

我想到的另一个选项是设置一个布尔值来确定是否覆盖方法caretRectForPosition。这可能吗?

【问题讨论】:

  • CGRect rect = [super caretRectForPosition:position]; 怎么样?
  • 有效!请将其添加为答案,以便我接受。谢谢
  • 完成,很高兴它帮助了你:)

标签: ios objective-c ios5 ios6


【解决方案1】:

好吧,您可以检查您的标志并相应地返回(零矩形或super 实现)。像这样的:

- (CGRect)caretRectForPosition:(UITextPosition *)position
{
    return self.isCaretEnabled ? [super caretRectForPosition:position] : CGRectZero;
}

isCaretEnabled 当然是你的BOOL 属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-30
    • 1970-01-01
    • 2019-03-12
    相关资源
    最近更新 更多