Graphics Programs Reference
In-Depth Information
@property (nonatomic) NSTimeInterval dateCreated;
@property (nonatomic, strong) NSString * imageKey;
@property (nonatomic, strong) NSData * thumbnailData;
@property UNKNOWN_TYPE UNKNOWN_TYPE thumbnail;
@property (nonatomic, strong) UIImage *thumbnail;
@property (nonatomic) double orderingValue;
@property (nonatomic, strong) NSManagedObject *assetType;
- (void)setThumbnailDataFromImage:(UIImage *)image;
@end
Notice that the types of a few properties have changed, like valueInDollars and
dateCreated . The type int32_t is just like an int , so we don't have to worry about
that. However, dateCreated is now an NSTimeInterval instead of an NSDate .
NSDate , as we know it, represents a date. You might expect for it to store the current
year, month, day, hour, etc., but this would cause issues for other types of calendars. (We
use the Gregorian calender; other nations may not.) Instead, an NSDate stores the num-
ber of seconds since a fixed point in time: January 1st, 2001 in Gregorian. Thus, it is per-
fectly reasonable to represent an NSDate as an NSTimeInterval , which is just a type
definition for double .
However, this change in type causes an issue with the code in Homepwner where we treat
this variable as an NSDate object. In DetailViewController.m , locate
viewWillAppear: and substitute the following line of code:
[dateLabel setText:[dateFormatter stringFromDate:[item dateCreated]]];
// Convert time interval to NSDate
NSDate *date = [NSDate dateWithTimeIntervalSinceReferenceDate:[item dateCreated]];
[dateLabel setText:[dateFormatter stringFromDate:date]];
Next, in BNRItem.m , copy the setThumbnailFromImage: method from your old
BNRItem.m to the new one:
- (void)setThumbnailDataFromImage:(UIImage *)image
{
CGSize origImageSize = [image size];
CGRect newRect = CGRectMake(0, 0, 40, 40);
float ratio = MAX(newRect.size.width / origImageSize.width,
newRect.size.height / origImageSize.height);
UIGraphicsBeginImageContextWithOptions(newRect.size, NO, 0.0);
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:newRect
cornerRadius:5.0];
[path addClip];
CGRect projectRect;
projectRect.size.width = ratio * origImageSize.width;
projectRect.size.height = ratio * origImageSize.height;
projectRect.origin.x = (newRect.size.width - projectRect.size.width) / 2.0;
 
Search WWH ::




Custom Search