Changing label text size in code - xcode

I have to adjust my label text size depending of the device (iPad, iPhone) and these orders just doesn't seem to work. I have my label declared in the interface, set on property as IBOutlet and synthesized. Then:
label.font = [UIFont fontWithName:#"Arial Black" size:50.0];
label.minimumFontSize = 50.0;
The size just doesn't change. :S
Any advices?

It may be useful to you to use:
[label setFont:[UIFont systemFontOfSize:35]];
or
[label setFont: [UIFont fontWithName:#"Arial" size:50.0]];

There's nothing wrong in your code except for the font you are using.
It should be :
label.font = [UIFont fontWithName:#"Arial" size:50];
Actually Arial Black is not supported by iphone.
You can check the list of the fonts supported by iPhone here.

You should take a look of the fonts you can use by Default in iOS
here is a link: iOS Links http://iosfonts.com/

Related

Misaligned NSAttributedString in macOS NSStatusItem's button

I would like to display a two-line NSAttributedString as the button title of the NSStatusItem of my macOS app.
However, it seems to move the text up a few pixels and, thus, cut it off. This problem did not occur before macOS Big Sur.
Workaround
With some effort I managed to generate an NSImage of the text and use it as the button's image.
Question
Is there any way to position the NSAttributedString correctly without using an image?
I found a way to workaround this problem, but I don’t know if this way is correct, the code with Objetive-C is as follows
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
CGFloat minMaxLineHeight = (font.pointSize - font.ascender + font.capHeight);
[style setMinimumLineHeight:minMaxLineHeight];
[style setMaximumLineHeight:minMaxLineHeight];
NSRange range = NSMakeRange(0, text.length);
[attriString addAttribute:NSParagraphStyleAttributeName
value:style
range:range];
[attriString addAttribute:NSBaselineOffsetAttributeName
value:#(-3.5)
range:range];

iOS8 How to set TabBarItem images

It seems something has changed with iOS8 and now none of my tab bar icons are showing up properly. Most of the time they don't show until the tab is active:
But sometimes they don't show up at all and give me just a big blue box (like whenever I dismiss a view that covered the whole window):
This is what I did pre iOS8:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"paintbrush-black.png"]];
tabBarItem1.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
tabBarItem1.title = #"";
as mentioned, if you take a look at:
https://developer.apple.com/Library/ios/documentation/UIKit/Reference/UITabBarItem_Class/index.html#//apple_ref/occ/instm/UITabBarItem/setFinishedSelectedImage:withFinishedUnselectedImage:
you will notice that this method is deprecated, try to change:
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:#"paintbrush-white.png"] withFinishedUnselectedImage:[UIImage imageNamed:#"paintbrush-black.png"]];
to:
[tabBarItem1 setImage:[[UIImage imageNamed:#"paintbrush-white.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:#"paintbrush-black.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
You may also have problems with the image size, depends of the size of image when testing in iPhone 5 screen and iPhone 6 screen for #2x images
Did you try setSelectedImage:?
UIImage *image = [UIImage imageNamed:#"img.png"]
[tabItem setSelectedImage:image];
It works on my part.
This method is deprecated in iOS 8:
Use initWithTitle:image:selectedImage: or the image and selectedImage properties along with UIImageRenderingModeAlwaysOriginal

iOS 7: What is UIBarButtonItem's default font?

What is the default font of the title of a UIBarButtonItem with a style of UIBarButtonItemStyleDone?
The following just returns nil:
[doneBarButtonItem titleTextAttributesForState:UIControlStateNormal]
[UIFont boldSystemFontOfSize:17]
Note: I confirmed this by doing:
UIFont *font = [UIFont boldSystemFontOfSize:17];
[doneBarButtonItem setTitleTextAttributes:#{NSFontAttributeName: font}
forState:UIControlStateNormal];
And then, I took screenshots of the before & after and compared them. They were identical.
You can retrieve the default font for a UILabel (which includes UIBarButton's title label) by querying
UIFont.systemFont(ofSize: UIFont.labelFontSize)

Code equivalent for size property in Interface Builder

I'm creating some NSTableColumns dynamically and they appear too tall in the table. In the Interface Builder there is a general setting to adjust the object size (mini, small, regular). Is there any code equivalent for this or should I simply select the font manually?
Update
I found that I can get the font with:
NSFont *font = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]];
However, the row height doesn't match the items' height. Setting the font in code does nothing with the row height. I use NSTextFieldCells and NSPopUpButtonCells as data cells.
Oh, and I'm building for 10.6.
In addition to changing the font, you need to set the control size of the cell.
NSCell *theCell = ...;
[theCell setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]]];
[theCell setControlSize:NSMiniControlSize];
Apple is now providing an official guide for this.
Here's copied code snippet.
float fontSize = [NSFont systemFontSizeForControlSize:NSMiniControlSize];
NSCell *theCell = [theControl cell];
NSFont *theFont = [NSFont fontWithName:[[theCell font] fontName] size:fontSize];
[theCell setFont:theFont];
[theCell setControlSize:NSMiniControlSize];
[theControl sizeToFit];

iphone ipad change text field colour

please, how can I change the color of the text field background and the colour of place holder?
I saw this answer
here in stack, change bkgrnd
but Is not clear where to call this
[UIColor colorWithRed:0.2f green:0.3f blue:0.4f alpha:0.50001f];
shall I override the UITextField.h? where?
or where shall I change the colour?
and for the changing of the place holder, but it doesn't work!
stack, change holder.
You can overwrite UITextField and do this in the init method. But I would highly recommend to do simply after you created your UITextField
textField.backgroundColor = [UIColor colorWithRed:0.2f green:0.3f blue:0.4f alpha:0.50001f];
To change the background of your textfield :
yourTextField.backgroundColor = [UIColor yellowColor];
To change the placeholder text color :
[yourTextField setValue:[UIColor blackColor] forKeyPath:#"_placeholderLabel.textColor"];

Resources