Muju Muju - 4 months ago 23
Objective-C Question

How to add font awesome icon in an NSArray in Objective C

First I created class name as

NSString+FontAwesome.h
and
NSString+FontAwesome.m
in
NSString+FontAwesome.h
like following way

@import Foundation;
typedef NS_ENUM(NSUInteger, FaIcon) {
FaMoonO = 0xf186,
FaArchive = 0xf187
};

@interface NSString (AwesomeString)

//creates a string with the font awesome character
+(NSString*)awesomeIcon:(FaIcon)index;

@end


and in
NSString+FontAwesome.m
code is like this

#import "NSString+FontAwesome.h"
@implementation NSString (AwesomeString)

+(NSString*)awesomeIcon:(FaIcon)index
{
return [NSString stringWithFormat:@"%C", (unichar)index];
}

@end


I am using code like this for label and it work properly.

label.font = [UIFont fontWithName:@"FontAwesome" size:30];
label.textColor = [UIColor whiteColor];
label.text = [NSString awesomeIcon:FaBook];


But I want to used it in array any advice.
My array code is like this.

iconarray =[[NSMutableArray alloc] initWithObjects:[NSString awesomeIcon:FaArchive],nil];


But it don't show me anything. How can I add
[UIFont fontWithName:@"FontAwesome" size:30]
in an array.
Please help..

Answer

.h file

@import Foundation;
typedef NS_ENUM(NSUInteger, FaIcon) {
FaMoonO = 0xf186,
    FaArchive = 0xf187
};

@interface NSString (AwesomeString)

//creates a string with the font awesome character
+(NSString*)awesomeIcon:(FaIcon)index;

@end

Used Custom UITableViewCell then in table view used your same code

label.font = [UIFont fontWithName:@"FontAwesome" size:30];
label.textColor =  [UIColor whiteColor];
label.text =  [NSString awesomeIcon:FaBook];

for label. Then add that label text in array as

iconarray =[[NSMutableArray alloc] initWithObjects:[NSString awesomeIcon:FaInfo],[NSString awesomeIcon:FaEye],nil];
Comments