[ios] Improved text thickness in combination with branch name

Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
Yannik Bloscheck
2025-08-27 16:30:29 +02:00
committed by Konstantin Pastbin
parent c039d599e4
commit 49391bb39e
12 changed files with 36 additions and 25 deletions

View File

@@ -90,7 +90,7 @@ extension PlacePageHeaderViewController: PlacePageHeaderViewProtocol {
}
let titleAttributes: [NSAttributedString.Key: Any] = [
.font: StyleManager.shared.theme!.fonts.medium20,
.font: StyleManager.shared.theme!.fonts.semibold20,
.foregroundColor: UIColor.blackPrimaryText()
]

View File

@@ -1349,7 +1349,7 @@
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" verticalHuggingPriority="750" text="Хинкальная" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lR4-to-4wX">
<rect key="frame" x="16" y="20" width="267" height="25"/>
<fontDescription key="fontDescription" type="system" weight="medium" pointSize="20"/>
<fontDescription key="fontDescription" type="system" weight="semibold" pointSize="20"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>

View File

@@ -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];
}

View File

@@ -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]
};
}

View File

@@ -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>