Is there a way to change the size of the font in a UIToolbar? My text does not fit so I need to make it smaller.
Thanks!
Here is one example. I am not sure what you want, but you can resize the font size of uibarbuttonitem in uitoolbar.
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,10,15)];
label.font = [UIFont systemFontOfSize:15.0];
label.textColor = [UIColor blackColor];
label.backgroundColor = [UIColor clearColor];
//label.adjustsFontSizeToFitWidth = YES;
label.textAlignment = UITextAlignmentCenter;
label.text = #"Bar";
UIBarButtonItem *item2 = [[UIBarButtonItem alloc]
initWithCustomView:label];
Related
In storyboard the font size for UILabel can't be increased above 300. How this limit occurs and how can we overcome this limit.
I think its not possible from storyboard but can be done from code.
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 500, 500)];
label.textAlignment = NSTextAlignmentNatural;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:#"Arial" size:400];
label.text = #"AI";
You can probably use your existing label instead of creating a brand new one in code:
label.font = [label.font fontWithSize:400];
I am creating a UILabel in a custom view and want it to match the typography (font and size) of the default UINavigationBar labels.
Like so:
UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 160.0, 44.0) ];
titleLabel.textAlignment = NSTextAlignmentCenter;
titleLabel.textColor = [UIColor whiteColor];
//titleLabel.backgroundColor = [UIColor redColor];
titleLabel.center = CGPointMake([self screenWidth] / 2.0, 42.0);
titleLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:(18.0)];
titleLabel.text = #"Forgot Password";
Does anyone know the font and point size?
I would like to be able to control the position of the title in a UInavigationBar. For example, right now my titles are centered, but for some views, I need to shift the title origin a few px to the left or so. Is this possible?
Thank you!
You can add a custom titleView to your navigation item, and place an off-center UILabel in it to hold your title. Another easier way, might be to just append a space character or two to the end of your title if that gives you the amount of displacement you need.
your code here
- (void) customNavBarTitleWithText:(NSString *) text andFontsize:(float) fontsize
{
// Custom nav bar back button
UIImage *img = [UIImage imageNamed:#"back_btn.png"];
UIButton *backbtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, img.size.width, img.size.height)];
[backbtn setImage:img forState:UIControlStateNormal];
[backbtn addTarget:self action:#selector(backBtnClicked) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *backBarBtn = [[UIBarButtonItem alloc] initWithCustomView:backbtn];
[self.navigationItem setLeftBarButtonItem:backBarBtn];
//Custom nav bar title
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
label.backgroundColor = [UIColor clearColor];
label.font = [UIFont boldSystemFontOfSize:fontsize];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = NSTextAlignmentCenter;
// Use UITextAlignmentCenter for older SDKs.
label.textColor = [UIColor whiteColor]; // change this color
self.navigationItem.titleView = label;
label.text = text;
label.lineBreakMode = NSLineBreakByWordWrapping;
label.numberOfLines = 0;
[label sizeToFit];
// Set nav bar background image
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"top_bar_bg.png"] forBarMetrics:UIBarMetricsDefault];
}
in there:
label.textAlignment = NSTextAlignmentCenter;
you can use another mode: NSTextAlignmentLeft, NSTextAlignmentRight, NSTextAlignmentJustified, etc..
Hope it work for you!
In my UINavigationBar I have a multi line title, I am using the following the code to setup:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 480, 50)];
label.backgroundColor = [UIColor clearColor];
label.numberOfLines = 2;
label.font = [UIFont boldSystemFontOfSize: 15.0f];
label.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.text = #"Headloss due to Friction (Hazen Williams Eq.)";
self.navigationItem.titleView = label;
Since this is on a sub-view it has a "Back" button, added by the UINavigationController. So I figured that by adding the label.textAlignment = NSTextAlignmentCenter; my title would be centered, but it's actually centering my title from the end of my "Back" button to the end of my screen.
How can I override this so that my title is actually centered based on my screen dimension, (basically, the way it would be by default should the back button not be present).
Good question that's pretty tough. If I find a more elegant solution I'll edit my answer but this is what I came up with:
UIView *spaceView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 20)];
UIBarButtonItem *space = [[UIBarButtonItem alloc] initWithCustomView:spaceView];
self.navigationItem.rightBarButtonItems = [NSArray arrayWithObject:space];
And just adjust the width of the UIView for how far you want your titleLabel to move.
I have a UICollectionViewController and trying to set navigation title..
but none of these works...It does not show the text!
self.titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.titleLabel.backgroundColor = [UIColor clearColor];
self.titleLabel.font = [UIFont fontWithName:#"ArialHebrew-Bold" size:15];
self.titleLabel.shadowColor = [UIColor colorWithWhite:0.0 alpha:0.5];
self.titleLabel.textAlignment = NSTextAlignmentCenter;
self.titleLabel.textColor = [UIColor whiteColor];
self.titleLabel.text = [self.navigationItem title];
self.navigationItem.titleView = self.titleLabel;
[self.titleLabel setText:#"title"];
self.navigationItem.title = #"The title";
Make the frame of your new label bigger. The height of a nav bar is fixed at 44 pixels.
For example: CGRectMake(100,0,120,44);
The width and origins depend on what else is on the navbar, and the width of the navbar.