ios 7 typography on labels and UIFont - ios

I have the following code:
UILabel *registerLabel = [ [UILabel alloc ] initWithFrame:CGRectMake(20.0, 90.0, [self screenWidth], 43.0) ];
registerLabel.textAlignment = NSTextAlignmentLeft;
registerLabel.textColor = [UIColor whiteColor];
registerLabel.backgroundColor = [UIColor blackColor];
registerLabel.font = [UIFont fontWithName:#"Helvetica Neue" size:(20.0)];
//registerLabel.adjustsFontSizeToFitWidth = YES;
registerLabel.text = #"Register";
But I see in some of the ios 7 demo apps (like calendar) the font is large but much thinner. I tried using Helevetica Neue Light but that doesn't work. Is there a way to make the font thinner or what font are they using?

I found the answer to be this:
registerLabel.font = [UIFont fontWithName:#"HelveticaNeue-Light" size:(36.0)];
.font is what you need

Related

NSAttributedString with sub/superscript on iOS 13 [duplicate]

Trying to display super/subscript text using NSAttributedString in a UITextView seems broken in iOS13 - unless anyone knows otherwise?
Curiously if I use the UIFont systemFont then it works - but if I use any other font it doesn't.
See below for my code to setup a UITextView in my test app.
- (void)viewDidLoad
{
[super viewDidLoad];
UIFont* font = [UIFont systemFontOfSize:32];
//UIFont* font = [UIFont fontWithName:#"Helvetica Neue" size:32];
//UIFont* font = [UIFont fontWithName:#"Courier" size:32];
//UIFont* font = [UIFont fontWithName:#"Arial" size:32];
NSMutableAttributedString* as = [[NSMutableAttributedString alloc] initWithString:#"Super2Script" attributes:#{NSFontAttributeName : font}];
[as addAttribute:(NSString*)kCTSuperscriptAttributeName value:#(1) range:NSMakeRange(5, 1)];
UITextView* tv = [[UITextView alloc] initWithFrame:CGRectZero];
tv.attributedText = as;
[tv sizeToFit];
[self.view addSubview:tv];
tv.center = CGPointMake(self.view.bounds.size.width / 2, self.view.bounds.size.height / 2);
}
Simple 'fix' for this one.
It appears kCTSuperscriptAttributeName no longer works in iOS13 (for non-system fonts.) You need to use NSSuperscriptAttributeName instead. No idea where the definition for this lives (which header) so the actual string value required is "NSSuperScript"

Navigation Title Chopped with external Font 'FuturaStd-Book'

Title chopped in Navigation with external Font 'FuturaStd-Book'.
Tried to decreased Font size with following code but still title chopped.
[[UINavigationBar appearance] setTitleTextAttributes:#{NSFontAttributeName:[UIFont fontWithName:#"FuturaStd-Book" size:16]}];
Kindly help me on this...
Following code to Align the navigationItem title. (Only Works from iOS 11 - but the Navigation back and Title y position differs )
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.alignment = NSTextAlignmentCenter;
style.firstLineHeadIndent = 1.0f;
style.lineSpacing = 2; //Change spacing between lines
style.paragraphSpacing = 2; //Change space between paragraphs
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor blackColor],
NSBackgroundColorAttributeName:[UIColor clearColor],
NSFontAttributeName:[UIFont fontWithName:#"FuturaStd-Book" size:18],
NSParagraphStyleAttributeName: style }];
You've to use the titleView of the navigationItem. Try this in your VC:
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 400.0, 44.0)];
headerLabel.textAlignment = NSTextAlignmentCenter;
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.text = #"Register";
headerLabel.font = [UIFont fontWithName:#"FuturaStd-Book" size:16];
headerLabel.textColor = [UIColor blackColor];
self.navigationItem.titleView = headerLabel;
Output:

UINavigationBar: Changing the font programmatically

I'm implementing a UINavigationBar with some text on it but I want to change the font in the UINavigationBar text any of you knows if is posible to change font in the text programmatically?
I'll really appreciate your help
From iOS 7 and later:
NSShadow* shadow = [NSShadow new];
shadow.shadowOffset = CGSizeMake(0.0f, 1.0f);
shadow.shadowColor = [UIColor redColor];
[[UINavigationBar appearance] setTitleTextAttributes: #{
NSForegroundColorAttributeName: [UIColor greenColor],
NSFontAttributeName: [UIFont fontWithName:#"Helvetica" size:20.0f],
NSShadowAttributeName: shadow
}];

AttributedString in UINavigationBar not showing both lines of text

I am trying to set a two line label in my UINavigationBar. When I do the following, it only shows one line (the part before the line break).
NSString *title = #"First line of title is bigger\nSecond line of title is smaller";
NSDictionary *attribute1 = #{NSForegroundColorAttributeName: [UIColor colorWithRed:148/255.0f green:147/255.0f blue:147/255.0f alpha:1],
NSFontAttributeName: [UIFont boldSystemFontOfSize: 14.0f]};
NSDictionary *attribute2 = #{NSForegroundColorAttributeName: [UIColor colorWithRed:148/255.0f green:147/255.0f blue:147/255.0f alpha:1],
NSFontAttributeName: [UIFont boldSystemFontOfSize: 10.0f]};
const NSRange line1Range = {0, 29};
const NSRange line2Range = {31, 30};
NSMutableAttributedString *attributedText =[[NSMutableAttributedString alloc] initWithString:title];
[attributedText setAttributes: attribute1 range:line1Range];
[attributedText setAttributes: attribute2 range:line2Range];
UILabel *label = [[UILabel alloc] init];
label.attributedText=attributedText;
self.navigationItem.titleView = label;
[self.navigationItem.titleView sizeToFit];
For comparison, the following shows both line. The following is for comparison only. The top version is what I need.
UILabel *label = [[UILabel alloc] init];
label.backgroundColor = [UIColor clearColor];
label.numberOfLines = 2;
label.font = [UIFont boldSystemFontOfSize: 14.0f];
label.textColor = [UIColor colorWithRed:148/255.0f green:147/255.0f blue:147/255.0f alpha:1];
label.text = #"First line of title is bigger\nSecond line of title is smaller";
self.navigationItem.titleView = label;
[self.navigationItem.titleView sizeToFit];
Any help getting the top version to work correctly?
It appears that calling label.sizeToFit() before self.navigationItem.titleView = label displays the NSAttributedString title correctly.
(Swift, iOS8.1, XCode 6.1.1)
Easy problem, easy solution. Even if you are using attributedText instead of text, you still need to:
label.numberOfLines = 0;

Centering Label Vertically in UINavigationBar TitleView

I'm not having much luck centering vertically the label I'm adding to the TitleView on the UINavigationBar. You can see what it looks like below.
This is how I'm adding the label:
UILabel *titleLabel = [[UILabel alloc] init];
titleLabel.text = NSLocalizedString(#"activeSessionsTitle",#"");
titleLabel.font = [Util SETTING_NEO_HEADER_FONT];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.shadowColor = [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.25f];
titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f);
[titleLabel sizeToFit];
super.navigationItem.titleView = titleLabel;
I think the reason why it's doing this is there is something weird with the actual font I'm using -- as I've had to do a lot of repositioning inside of buttons and such. I've been able to solve the issue everywhere but the navigation bar.
Opening up an old Question, but I found this to be very useful.
iOS 5 allows your to use [UINavigationBar appearance] which is great for changing the Title bar's title view without the need for a custom UIView:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor redColor],
UITextAttributeTextColor,
[UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.8],
UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, -1)],
UITextAttributeTextShadowOffset,
[UIFont fontWithName:#"HelveticaNeue" size:25.0f],
UITextAttributeFont,
nil]];
Sometimes, depending on the UIFont that you use, the title view may be vertically off.
To fix this, you can use:
[self.navigationBar setTitleVerticalPositionAdjustment:(float) forBarMetrics:UIBarMetricsDefault];
(float) being a positive value to push the titleView down, and a negative value to push the titleView up.
I hope this helps.
I ended up using a combination of the answer RPM left and one of the comments on my question. This is what ultimately fixed it for me:
UIView *customTitleView = [[UIView alloc] init];
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 3.0f, 200.0f, 30.0f)];
titleLabel.text = titleString;
titleLabel.font = [Util SETTING_NEO_HEADER_FONT];
titleLabel.textColor = [UIColor whiteColor];
titleLabel.backgroundColor = [UIColor clearColor];
titleLabel.textAlignment = UITextAlignmentCenter;
titleLabel.shadowColor = [UIColor colorWithRed:0.0f/255.0f green:0.0f/255.0f blue:0.0f/255.0f alpha:0.25f];
titleLabel.shadowOffset = CGSizeMake(0.0f, -1.0f);
[titleLabel sizeToFit];
customTitleView.frame = CGRectMake(self.navigationItem.titleView.frame.size.width/2 - titleLabel.frame.size.width/2, self.navigationItem.titleView.frame.size.height/2 - titleLabel.frame.size.height/2, titleLabel.frame.size.width, titleLabel.frame.size.height);
[customTitleView addSubview:titleLabel];
[titleLabel release];
[self.navigationItem setTitleView:customTitleView];
[customTitleView release];
If you're using this chunk of code, you may have to play with the "y" value on the title label's initWithFrame: call. I have it set to 3.0f, but you may have to adjust it a bit for your own usage.
The reason the other solutions didn't seem to work for me is they would go off-center horizontally depending if I had one barbutton (left or right). If there were no bar buttons it was fine, and if there were two it was fine. But one would cause it to go off-center.
I dont think this has anything to do with your font. I have also used titleView and I think the way it lays out the view in a weird way and doesnt take into consideration what your view size is.
You could also set the frame of your label view as such
titleLabel.frame = CGRectMake(self.navigationItem.titleView.frame.size.width/2 - titleLabel.frame.size.width/2, self.navigationItem.titleView.frame.size.height/2 - titleLabel.frame.size.height/2, titleLabel.frame.size.width, titleLabel.frame.size.height);
self.navigationItem.titleView = titleLabel;
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName:UIFont(name:"Exo2-Bold", size: 18) as! AnyObject,NSForegroundColorAttributeName:UIColor.whiteColor()]

Resources