Skip to content

Instantly share code, notes, and snippets.

@CreatureSurvive
Created July 23, 2018 14:53
Show Gist options
  • Select an option

  • Save CreatureSurvive/9187af2cce0245153a08a4a14415239a to your computer and use it in GitHub Desktop.

Select an option

Save CreatureSurvive/9187af2cce0245153a08a4a14415239a to your computer and use it in GitHub Desktop.
Example of a custom PSTableCell
#import <Preferences/PSTableCell.h>
#import <Preferences/PSSpecifier.h>
@interface CSPVersionCell : PSTableCell
@end
#import "CSPVersionCell.h"
#import "../Managers/CSPPackageManager.h"
@implementation CSPVersionCell {
NSString *_bundleID;
NSString *_label;
NSString *_version;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier specifier:(PSSpecifier *)specifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier specifier:specifier];
_bundleID = [specifier propertyForKey:@"bundleID"];
_label = [specifier propertyForKey:@"label"] ? : @"Version:";
_version = _bundleID ? [CSPPackageManager packageVersionForBundleID:_bundleID] : @"missing bundleID";
self.textLabel.text = _label;
self.detailTextLabel.text = _version;
self.accessoryView.hidden = YES;
self.imageView.hidden = YES;
// [self checkForUpdate];
return self;
}
- (instancetype)initWithSpecifier:(PSSpecifier *)specifier {
self = [self initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil specifier:specifier];
return self;
}
- (UIImage *)updateIconOfColor:(UIColor *)color {
CGRect rect = CGRectMake(0, 0, 10, 10);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment