UILabel.center在文本被修改或视图加载时未设置

时间:2014-12-20 11:34:05

标签: ios uilabel

我遇到了UILabels的.center属性问题。我需要根据光标在textView中的位置移动标签。我的代码如下:

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if([[textView text] length] > 160){
        return NO;
    }

    //CharacterLimitLabel.text = [NSString stringWithFormat:@"%u", 160 - [[textView text] length]];

    [self setCharacterLabelPosition];
    return YES;
}

-(void)setCharacterLabelPosition{
    CGPoint cursorPosition = [CreateTextView caretRectForPosition:CreateTextView.selectedTextRange.start].origin;
    cursorPosition.x = cursorPosition.x + CreateTextView.frame.origin.x + 45;
    cursorPosition.y = cursorPosition.y + CreateTextView.frame.origin.y + 15;

    CharacterLimitLabel.center = cursorPosition;
}

这在很大程度上起作用,但是,当我取消注释标签的设置时,标签不再改变其中心。

0 个答案:

没有答案
相关问题