Created
March 31, 2014 21:30
-
-
Save mcconkiee/9902822 to your computer and use it in GitHub Desktop.
font awesome as uilabel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//assumes FontAwesome.ttf is a resource and added to plist | |
NSInteger ti = (NSInteger)self.quizDuration ; | |
NSInteger seconds = ti % 60; | |
NSInteger minutes = (ti / 60) % 60; | |
NSInteger hours = (ti / 3600); | |
NSString *TTLE = [NSString stringWithFormat:@"%02li:%02li:%02li ", (long)hours, (long)minutes, (long)seconds]; | |
//f01d = play | |
//f04c = pause | |
int sze = 15; | |
unichar symbol = 0xf04c;//play (fontawesome) | |
UIButton *bt = (UIButton*)self.navigationItem.titleView; | |
UIColor *clr = [UIColor whiteColor]; | |
if (!self.quizTimer) { | |
symbol = 0xf01d; | |
clr = [UIColor applicationOrangeColor]; | |
} | |
TTLE = [TTLE stringByAppendingString:[NSString stringWithFormat:@"%C",symbol]]; | |
NSMutableAttributedString *aTTLE = [[NSMutableAttributedString alloc] initWithString:TTLE | |
attributes:[NSDictionary dictionaryWithObjectsAndKeys: | |
[UIFont applicationFontOpenSansBold:sze],NSFontAttributeName, | |
clr,NSForegroundColorAttributeName | |
, nil]]; | |
[aTTLE setAttributes:[NSDictionary dictionaryWithObjectsAndKeys: | |
[UIFont fontWithName:@"FontAwesome" size:15],NSFontAttributeName, | |
clr,NSForegroundColorAttributeName | |
, nil] | |
range:NSMakeRange(TTLE.length - 1, 1)]; | |
[bt setAttributedTitle:aTTLE forState:UIControlStateNormal]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment