如何在NSString的末尾添加UIButton?

时间:2015-10-13 22:13:13

标签: ios objective-c uibutton nsstring

有人可以帮助我了解如何在UIButton结束时添加NSString吗?我试过了:

[self.mystring substringToIndex:25]并再次分配

self.mystring.text = [self.mystring.text stringByAppendingString:@"...ReadMore"];

我怎样才能使这个' ReadMore'作为UIButton

1 个答案:

答案 0 :(得分:0)

在UITextView

上使用UITapGestureRecognizer会更容易
- (IBAction)tapOnTextView:(UITapGestureRecognizer *)sender {
    CGPoint location = [sender locationInView:self.textView];
    NSRange *range = [self.textView.text rangeOfString: @"...Read More"];
    UITextPosition *beginning = self.textView.beginningOfDocument;
    UITextPosition *start = [textView positionFromPosition:beginning offset:range.location];
    UITextPosition *end = [textView positionFromPosition:start offset:range.length];
    UITextRange *textRange = [textView textRangeFromPosition:start toPosition:end];
    CGRect readMoreRect = [self.textView firstRectForRange:textRange];
    if(CGRectContainsPoint(readMoreRect,location)){
        //load more text or something
    }
}

您可以使用属性字符串来制作...阅读更多不同的颜色,以便用户知道他们可以点击它。