Reputation: 6255
I am looking for a simpler way to set a weight for NSFont
.
Right now I can only do:
void SetWeight(NSFont font, int weight)
{
NSFontManager *manager = [NSFontManager sharedFontManager];
int currentWeight = [manager weightOfFont:font];
while( currentWeight != weight )
{
if( currentWeight >= weight )
{
[manager convertWeight:NO ofFont:font];
currentWeight--;
}
else
{
[manager convertWeight:YES ofFont:font];
currentWeight++;
}
}
}
Is there an easier way to set the appropriate weight for NSFont? Specifically I'm looking for eliminating the loop
Upvotes: 3
Views: 1929
Reputation: 3003
Does this method from the NSFontManager fit for this purpose?
- (NSFont *)fontWithFamily:(NSString *)family
traits:(NSFontTraitMask)fontTraitMask
weight:(NSInteger)weight
size:(CGFloat)size
Upvotes: 4
Reputation: 2940
For a button for example
button.font = [NSFont systemFontOfSize:13 weight:NSFontWeightMedium];
Upvotes: 1