0

可能重复:
在 iPhone 上的 UILabel 中查找特定字符的位置

How can i get the position of a specific string/substring in UILabel ? The UILabel is a multiline label and also has /n characters. Ultimately I should be able to draw another view in place of the position retrieved.

If not UILabel, could a UITextView be used to achieve results as expected above?

Thanks in advance.

4

1 回答 1

-1

此代码可以帮助您构建相同的逻辑..

@interface NSString ( containsCategory )
- (BOOL) containsString: (NSString*) substring;
@end

// - - - - 

@implementation NSString ( containsCategory )

- (BOOL) containsString: (NSString*) substring
{    
    NSRange range = [self rangeOfString : substring];
    BOOL found = ( range.location != NSNotFound );
    return found;
}

@end
于 2012-10-16T09:56:09.540 回答