[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

@@ -4,6 +4,7 @@ NS_ASSUME_NONNULL_BEGIN
@interface UIColor (MapsMeColor)
+ (UIColor *)black;
+ (UIColor *)blackPrimaryText;
+ (UIColor *)blackSecondaryText;
+ (UIColor *)blackHintText;

View File

@@ -68,6 +68,11 @@ static BOOL isNightMode = NO;
{
return StyleManager.shared.theme.colors.buttonRed;
}
+ (UIColor *)black
{
return StyleManager.shared.theme.colors.black;
}
+ (UIColor *)blackPrimaryText
{
return StyleManager.shared.theme.colors.blackPrimaryText;

View File

@@ -21,6 +21,7 @@ class DayColors: IColors {
var linkBlueDark = UIColor.accent
var buttonRed = UIColor(244, 67, 67, alpha100)
var buttonRedHighlighted = UIColor(183, 28, 28, alpha100)
var black = UIColor(0, 0, 0, alpha100)
var blackPrimaryText = UIColor(0, 0, 0, alpha87)
var blackSecondaryText = UIColor(0, 0, 0, alpha54)
var blackHintText = UIColor(0, 0, 0, alpha26)
@@ -83,6 +84,7 @@ class NightColors: IColors {
var linkBlueDark = UIColor.accent
var buttonRed = UIColor(244, 67, 67, alpha100)
var buttonRedHighlighted = UIColor(183, 28, 28, alpha100)
var black = UIColor(255, 255, 255, alpha100)
var blackPrimaryText = UIColor(255, 255, 255, alpha90)
var blackSecondaryText = UIColor(255, 255, 255, alpha70)
var blackHintText = UIColor(255, 255, 255, alpha30)

View File

@@ -32,6 +32,7 @@ let alpha100: CGFloat = 1.0
var linkBlueDark: UIColor { get }
var buttonRed: UIColor { get }
var buttonRedHighlighted: UIColor { get }
var black: UIColor { get }
var blackPrimaryText: UIColor { get }
var blackSecondaryText: UIColor { get }
var blackHintText: UIColor { get }

View File

@@ -56,4 +56,5 @@
var semibold15: UIFont { get }
var semibold16: UIFont { get }
var semibold18: UIFont { get }
var semibold20: UIFont { get }
}

View File

@@ -60,6 +60,7 @@ enum FontStyleSheet: String, CaseIterable {
case semibold15
case semibold16
case semibold18
case semibold20
}
extension FontStyleSheet: IStyleSheet {
@@ -127,6 +128,7 @@ extension FontStyleSheet: IStyleSheet {
case .semibold15: return fonts.semibold15
case .semibold16: return fonts.semibold16
case .semibold18: return fonts.semibold18
case .semibold20: return fonts.semibold20
}
}()
return .add { s in s.font = font }

View File

@@ -55,4 +55,5 @@ class Fonts: IFonts {
var semibold15 = UIFont.systemFont(ofSize: 15, weight:UIFont.Weight.semibold)
var semibold16 = UIFont.systemFont(ofSize: 16, weight:UIFont.Weight.semibold)
var semibold18 = UIFont.systemFont(ofSize: 18, weight:UIFont.Weight.semibold)
var semibold20 = UIFont.systemFont(ofSize: 20, weight:UIFont.Weight.semibold)
}

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>