Skip to content

Instantly share code, notes, and snippets.

@Dellybro
Last active Nov 23, 2016
Embed
What would you like to do?
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define ESTIMATEDPHONEHEIGHT ([[UIScreen mainScreen] bounds].size.height)/667
#define ESTIMATEDPHONEWIDTH ([[UIScreen mainScreen] bounds].size.width)/375
@interface CustomViews : NSObject
+(UIButton*)buttonWithString:(NSString *)string options:(NSDictionary*)options;
+(UILabel *)customLabel:(NSString*)text options:(NSDictionary*)options;
+(UIView*)coloredDot:(UIColor*)color;
+(UIImageView*)customImageViewNoBorder:(NSString*)imageString;
@end
@implementation CustomViews
+(UIImageView*)customImageViewNoBorder:(NSString*)imageString{
UIImageView* charImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageString]];
charImage.translatesAutoresizingMaskIntoConstraints = NO;
return charImage;
}
+(UIView*)coloredDot:(UIColor*)color{
UIView *newView = [[UIView alloc] init];
newView.backgroundColor = color;
newView.translatesAutoresizingMaskIntoConstraints = NO;
newView.layer.masksToBounds = YES;
return newView;
}
+(UILabel *)customLabel:(NSString*)text options:(NSDictionary*)options{
UILabel *label = [UILabel new];
label.text = text;
label.translatesAutoresizingMaskIntoConstraints = NO;
label.textAlignment = [options objectForKey:@"text-alignment"] ? [[options objectForKey:@"text-alignment"] integerValue] : NSTextAlignmentLeft;
label.textColor = [options objectForKey:@"font-color"] ? [options objectForKey:@"font-color"] : [UIColor blackColor];
label.font = [UIFont fontWithName:[options objectForKey:@"font-name"] size:[[options objectForKey:@"font-size"] floatValue]];
label.layer.cornerRadius = [[options objectForKey:@"corner-radius"] floatValue];
label.layer.borderColor = [options objectForKey:@"border-color"] ? (__bridge CGColorRef _Nullable)([options objectForKey:@"border-color"]) : [UIColor whiteColor].CGColor;
label.backgroundColor = [options objectForKey:@"background-color"] ? [options objectForKey:@"background-color"] : [UIColor clearColor];
label.layer.borderWidth = [options objectForKey:@"border-width"] || 0;
return label;
}
+(UIButton*)buttonWithString:(NSString *)string options:(NSDictionary*)options{
BouncingButton* newButton = [BouncingButton new];
newButton.titleLabel.textAlignment = NSTextAlignmentCenter;
newButton.translatesAutoresizingMaskIntoConstraints = NO;
newButton.layer.masksToBounds = YES;
[newButton setTitle:string forState:UIControlStateNormal];
[options objectForKey:@"font-color"] ? [newButton setTitleColor:[options objectForKey:@"font-color"] forState:UIControlStateNormal] : [newButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
// Options Layer
newButton.titleLabel.font = [UIFont fontWithName:[options objectForKey:@"font-name"] size:[[options objectForKey:@"font-size"] floatValue]];
newButton.layer.cornerRadius = [[options objectForKey:@"corner-radius"] floatValue];
newButton.layer.borderColor = [options objectForKey:@"border-color"] ? (__bridge CGColorRef _Nullable)([options objectForKey:@"border-color"]) : [UIColor whiteColor].CGColor;
newButton.backgroundColor = [options objectForKey:@"background-color"] ? [options objectForKey:@"background-color"] : [UIColor whiteColor];
newButton.layer.borderWidth = [options objectForKey:@"border-width"] ? [[options objectForKey:@"border-width"] floatValue] : 0;
return newButton;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment