mirror of
https://codeberg.org/comaps/comaps
synced 2026-01-02 19:13:44 +00:00
[ios] Improved text thickness in combination with branch name
Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
committed by
Konstantin Pastbin
parent
c039d599e4
commit
49391bb39e
@@ -17,42 +17,40 @@
|
||||
self.titleLabel.text = @"";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
bool hasBranchName = (result.branchText && result.branchText.length > 0 && ![title containsString:result.branchText]);
|
||||
|
||||
NSDictionary * selectedTitleAttributes = [self selectedTitleAttributes];
|
||||
NSDictionary * unselectedTitleAttributes = [self unselectedTitleAttributes];
|
||||
if (!selectedTitleAttributes || !unselectedTitleAttributes)
|
||||
if ((!selectedTitleAttributes || !unselectedTitleAttributes) && !hasBranchName)
|
||||
{
|
||||
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)];
|
||||
[attributedTitle addAttributes:unselectedTitleAttributes range:NSMakeRange(0, title.length)];
|
||||
|
||||
// Add branch with thinner font weight if present and not already in title
|
||||
if (hasBranchName) {
|
||||
NSMutableDictionary * branchAttributes = [unselectedTitleAttributes mutableCopy];
|
||||
[branchAttributes setValue:[UIFont regular17] forKey:NSFontAttributeName];
|
||||
NSAttributedString * branchString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", result.branchText] attributes:branchAttributes];
|
||||
[attributedTitle appendAttributedString:branchString];
|
||||
}
|
||||
|
||||
for (NSValue *rangeValue in highlightRanges) {
|
||||
NSRange range = [rangeValue rangeValue];
|
||||
if (NSMaxRange(range) <= result.titleText.length) {
|
||||
[attributedTitle addAttributes:selectedTitleAttributes range:range];
|
||||
if (NSMaxRange(range) <= attributedTitle.string.length) {
|
||||
[attributedTitle setAttributes:selectedTitleAttributes range:range];
|
||||
} else {
|
||||
NSLog(@"Incorrect range: %@ for string: %@", NSStringFromRange(range), result.titleText);
|
||||
NSLog(@"Incorrect range: %@ for string: %@", NSStringFromRange(range), attributedTitle.string);
|
||||
}
|
||||
}
|
||||
|
||||
// Add branch with thinner font weight if present and not already in title
|
||||
if (result.branchText && result.branchText.length > 0 && ![title containsString:result.branchText]) {
|
||||
NSDictionary * branchAttributes = isPartialMatching ? unselectedTitleAttributes : @{
|
||||
NSForegroundColorAttributeName : [selectedTitleAttributes objectForKey:NSForegroundColorAttributeName],
|
||||
NSFontAttributeName : [UIFont regular17]
|
||||
};
|
||||
NSAttributedString * branchString = [[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@" %@", result.branchText]
|
||||
attributes:branchAttributes];
|
||||
[attributedTitle appendAttributedString:branchString];
|
||||
}
|
||||
|
||||
|
||||
self.titleLabel.attributedText = attributedTitle;
|
||||
[self.titleLabel sizeToFit];
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
- (NSDictionary *)selectedTitleAttributes {
|
||||
return @{
|
||||
NSForegroundColorAttributeName : [UIColor blackPrimaryText],
|
||||
NSForegroundColorAttributeName : [UIColor black],
|
||||
NSFontAttributeName : [UIFont bold17]
|
||||
};
|
||||
}
|
||||
@@ -52,7 +52,7 @@
|
||||
- (NSDictionary *)unselectedTitleAttributes {
|
||||
return @{
|
||||
NSForegroundColorAttributeName : [UIColor blackPrimaryText],
|
||||
NSFontAttributeName : [UIFont regular17]
|
||||
NSFontAttributeName : [UIFont medium17]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="252" verticalCompressionResistancePriority="752" text="New York Cafe" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4FD-RE-ffF">
|
||||
<rect key="frame" x="56" y="12" width="181" height="20.5"/>
|
||||
<accessibility key="accessibilityConfiguration" identifier="searchTitle"/>
|
||||
<fontDescription key="fontDescription" type="boldSystem" pointSize="17"/>
|
||||
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="17"/>
|
||||
<color key="textColor" red="0.12941176470588234" green="0.12941176470588234" blue="0.12941176470588234" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<nil key="highlightedColor"/>
|
||||
<userDefinedRuntimeAttributes>
|
||||
|
||||
Reference in New Issue
Block a user