Files
comaps/iphone/Maps/UI/Search/TableView/MWMSearchCell.mm
Konstantin Pastbin e3e4a1985a Organic Maps sources as of 02.04.2025 (fad26bbf22ac3da75e01e62aa01e5c8e11861005)
To expand with full Organic Maps and Maps.ME commits history run:
  git remote add om-historic [om-historic.git repo url]
  git fetch --tags om-historic
  git replace squashed-history historic-commits
2025-05-08 21:10:51 +07:00

58 lines
1.6 KiB
Plaintext

#import "MWMSearchCell.h"
#import "SearchResult.h"
@interface MWMSearchCell ()
@property (weak, nonatomic) IBOutlet UILabel * titleLabel;
@end
@implementation MWMSearchCell
- (void)configureWith:(SearchResult * _Nonnull)result isPartialMatching:(BOOL)isPartialMatching {
NSString * title = result.titleText;
if (title.length == 0)
{
self.titleLabel.text = @"";
return;
}
NSDictionary * selectedTitleAttributes = [self selectedTitleAttributes];
NSDictionary * unselectedTitleAttributes = [self unselectedTitleAttributes];
if (!selectedTitleAttributes || !unselectedTitleAttributes)
{
self.titleLabel.text = title;
return;
}
NSMutableAttributedString * attributedTitle =
[[NSMutableAttributedString alloc] initWithString:title];
NSDictionary * titleAttributes = isPartialMatching ? unselectedTitleAttributes : selectedTitleAttributes;
NSArray<NSValue *> *highlightRanges = result.highlightRanges;
[attributedTitle addAttributes:titleAttributes range:NSMakeRange(0, title.length)];
for (NSValue *rangeValue in highlightRanges) {
NSRange range = [rangeValue rangeValue];
if (NSMaxRange(range) <= result.titleText.length) {
[attributedTitle addAttributes:selectedTitleAttributes range:range];
} else {
NSLog(@"Incorrect range: %@ for string: %@", NSStringFromRange(range), result.titleText);
}
}
self.titleLabel.attributedText = attributedTitle;
[self.titleLabel sizeToFit];
}
- (NSDictionary *)selectedTitleAttributes
{
return nil;
}
- (NSDictionary *)unselectedTitleAttributes
{
return nil;
}
@end