Skip to content

Instantly share code, notes, and snippets.

@jblocksom
Last active December 17, 2015 14:19
Show Gist options
  • Save jblocksom/5623153 to your computer and use it in GitHub Desktop.
Save jblocksom/5623153 to your computer and use it in GitHub Desktop.
//
// BNRPerson.h
// SalesReport
//
// Created by Jonathan Blocksom on 4/1/13.
// Copyright (c) 2013 Jonathan Blocksom. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface BNRPerson : NSObject
@property (copy) NSString *name;
@property NSUInteger sales;
@property (readonly) UIImage *photo;
- (id)initWithName:(NSString *)name image:(UIImage *)image;
// Initializes object with specified properties; if image
// is nil, will try to load image named same thing as name
@end
//
// BNRPerson.m
// SalesReport
//
// Created by Jonathan Blocksom on 4/1/13.
// Copyright (c) 2013 Jonathan Blocksom. All rights reserved.
//
#import "BNRPerson.h"
@interface BNRPerson()
@property (strong, readwrite) UIImage *photo;
// Declaring photo property readwrite here and as
// readonly in the .h file means we can modify it
// in the implementation but a user of the class
// cannot change it.
@end
@implementation BNRPerson
- (id)initWithName:(NSString *)name image:(UIImage *)image
{
self = [super init];
if (self) {
self.name = name;
if (image != nil) {
self.photo = image;
} else {
self.photo = [UIImage imageNamed:name];
}
}
return self;
}
@end
// Figure out the font
CTFontRef nameFont = CTFontCreateWithName(CFSTR("Palatino-BoldItalic"), NAME_HEIGHT, NULL);
// Get the glyphs
CGGlyph *gBuffer = malloc(length * sizeof(CGGlyph));
CTFontGetGlyphsForCharacters(nameFont, cBuffer, gBuffer, length);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment