-1

I am new to ios, Just need to clear two doubts:

1.I am aware that to set custom colors we use following method:

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

How do I find out from an Image what parameters for RGB are?(Its not an xcode question but I need to know).

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

setFont:[UIFont fontWithName:@"ExpertSans-ExtraBold" size:48.0f];
rdurand
  • 7,342
  • 3
  • 39
  • 72
nitz19arg
  • 417
  • 7
  • 18

5 Answers5

4

for set color

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

for set custom font

  1. How to use custom font in iOS Apps?
  2. iPhone Development: how to use custom fonts?
Community
  • 1
  • 1
DharaParekh
  • 1,730
  • 1
  • 10
  • 17
1

For number 1, if it's not an Xcode question, you have an app located in /Applications/Utilities on your mac, which lets you get the color of anything showing on your screen. (sorry, I don't know the name of the app in english, but it may have "color" in it). Then set the UIColor as you did : [UIColor colorWithRed: 100.0/255.0f green:200.0/255.0f blue:150.0/255.0f alpha:1.0];

For number 2, the name of the font is not always the name of the file. Once you added your font to the project, use this to log a list of all the font names available in your app :

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

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

Put this code in the AppDelegate in application:didFinishLaunchingWithOptions:

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

rdurand
  • 7,342
  • 3
  • 39
  • 72
0

Try to use this one

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

  2. You are right but i think you are not getting proper font name. So do this to get proper name of font. See in this pic and set this name to your font.

enter image description here

set your font like this

setFont:[UIFont fontWithName:@"BankGothic Md BT" size:48.0f];
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
0
  1. you can not get the whole image color but you can get the color of pixel

    iPhone Objective C: How to get a pixel's color of the touched point on an UIImageView? How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?

  2. For font you have to give font name not file name

      lblName.font=[UIFont fontWithName:@"Myriad Pro" size:15];  // where my file name is MyriadPro.ttf
    
Community
  • 1
  • 1
SAMIR RATHOD
  • 3,512
  • 1
  • 20
  • 45
0

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

Please also ensure when you are adding the font's file .ttf in your project it is also included in your target application. When you copy .ttf from other location to resource folder then it asks to copy to destination, and on that place you have to add it to the target application also by using check mark. If you suspect you haven't included to your target application. Please remove the files and add the again.

Hope this helps.

iEinstein
  • 2,100
  • 1
  • 21
  • 32
  • Question says "I have added the file name in "fonts provided by application"". – rdurand May 16 '13 at 07:30
  • @ashutosh: thanks buddy. I checked and the file is copied in project files perfectly. now when i generated log of font , its different from what i set. : font-family: ".Helvetica NeueUI"; font-weight: normal; font-style: normal; font-size: 17px – nitz19arg May 16 '13 at 08:19
  • can I be missing something else here in the process? – nitz19arg May 16 '13 at 08:19
  • But you have diificulty on this font ExpertSans-ExtraBold Please add nslog on label.font=[UIFont fontWithName:@"ExpertSans-ExtraBold" size:48.0f]; and print nslog and tell me the value you got – iEinstein May 16 '13 at 09:16