Set your own custom colors and fonts in UIColor

I am new to ios, just need to eliminate two doubts:

1. I know that we use the following method to set custom colors:

[UIColor colorWithRed: 127 green:127 blue:127 alpha:1] 

How to find out from the image what parameters for RGB? (This is not an xcode question, but I need to know).

2.How to add my own custom fonts to my project. I added the file name to the "fonts provided by the application." But I still can not get the result in the desired font. The file name is ExpertSans-ExtraBold.ttf. Below is the code:

 setFont:[UIFont fontWithName:@"ExpertSans-ExtraBold" size:48.0f]; 
-1
source share
5 answers

For number 1, if this is not an Xcode question, you have an application located in /Applications/Utilities on your Mac, which allows you to get the color of something displayed on your screen. (Sorry, I do not know the name of the application in English, but it may have a "color"). Then install UIColor just like you: [UIColor colorWithRed: 100.0/255.0f green:200.0/255.0f blue:150.0/255.0f alpha:1.0];

For number 2, the font name is not always the file name. Once you have added your font to the project, use it to register a list of all the font names available in your application:

 for (NSString* family in [UIFont familyNames]) { NSLog(@"%@", family); for (NSString* name in [UIFont fontNamesForFamilyName: family]) { NSLog(@" %@", name); } } 

Put this code in AppDelegate in application:didFinishLaunchingWithOptions:

Once you find your font name, use myLabel.font = [UIFont fontWithName:@"My-Font-Name" size:10]; to install the font.

+1
source

for color set

 [UIColor colorWithRed: 127.0/255.0f green:127.0/255.0f blue:127.0/255.0f alpha:1.0]; 

for custom font

+4
source

Try using this

  • [UIColor colorWithRed: 127/255.0f green:127/255.0f blue:127/255.0f alpha:1];

  • You are correct, but I think that you are not getting the correct font name. So do this to get the correct font name. Look at this picture and set this name for your font.

enter image description here

set the font as follows

 setFont:[UIFont fontWithName:@"BankGothic Md BT" size:48.0f]; 
0
source
0
source

Please check label.font = [UIFont fontWithName: @ "Font-Name" size: 10]; and put NSLog(@"%@",label.font); If you find zero, I think there is a problem in the name you give.

Also, make sure that when you add the .ttf font .ttf to your project, it is also included in your target application. When you copy .ttf from another location to the resource folder, it asks for a copy to the destination, and at this point you must add it to the target application using the checkmark as well. If you suspect that you didn’t make it to the target application. Delete the files and add them again.

Hope this helps.

0
source

Source: https://habr.com/ru/post/945137/


All Articles