Last active
August 29, 2015 14:02
-
-
Save Luavis/3db52fa95ec8277e5295 to your computer and use it in GitHub Desktop.
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
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] | |
#define UIColorFromRGBWithAlpha(rgbValue, alpha) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alpha] | |
#define UINavigationBarTintColor(uicolor) \ | |
NSArray *ver = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."]; \ | |
if ([[ver objectAtIndex:0] intValue] >= 7) { \ | |
self.navigationController.navigationBar.barTintColor = uicolor; \ | |
self.navigationController.navigationBar.translucent = NO; \ | |
} else { \ | |
self.navigationController.navigationBar.tintColor = uicolor; \ | |
} | |
#define LVS_MAKE_IMAGE_VIEW(IMAGE_VIEW, IMAGE_NAME, X, Y, WIDTH, HEIGHT) IMAGE_VIEW = [[UIImageView alloc] initWithImage:[UIImage imageNamed:IMAGE_NAME]]; \ | |
IMAGE_VIEW.frame = CGRectMake(X, Y, WIDTH, HEIGHT); | |
#define LVS_MAKE_LABEL(LABEL, TEXT, FONT_NAME, SIZE) \ | |
LABEL = [[UILabel alloc] init]; \ | |
LABEL.font = [UIFont fontWithName:FONT_NAME size:SIZE]; \ | |
LABEL.text = TEXT; \ | |
LABEL.frame = CGRectMake(0.0f, 0.0f, [TEXT sizeWithFont:LABEL.font].width, [LABEL.font lineHeight]); | |
#define LVS_MAKE_INPUT(INPUT, PLACEHOLDER, FONT_NAME, SIZE) \ | |
INPUT = [[UITextField alloc] init]; \ | |
INPUT.borderStyle = UITextBorderStyleRoundedRect; \ | |
INPUT.placeholder = PLACEHOLDER;\ | |
if(FONT_NAME) { \ | |
INPUT.font = [UIFont fontWithName:FONT_NAME size:SIZE]; \ | |
INPUT.frame = CGRectMake(0.0f, 0.0f, 100.0f, [INPUT.font lineHeight]); \ | |
} | |
// FORM must be id pointer | |
#define LVS_FORM(FORM, METHOD, ACTION) \ | |
FORM = @{@"method" : METHOD, @"action" : ACTION, @"input" : [[NSMutableDictionary alloc] init]}; \ | |
#define LVS_FORM_REGISTER_INPUT(FORM, NAME, INPUT) \ | |
[FORM[@"input"] setObject:INPUT forKey:NAME]; | |
#define LVS_FORM_SUBMIT(FORM, BLOCK) \ | |
{ \ | |
NSMutableArray * formData = [[NSMutableArray alloc] init];\ | |
for (id key in FORM[@"input"]) {\ | |
id obj = FORM[@"input"][key];\ | |
\ | |
if([obj isKindOfClass:[UITextField class]]) {\ | |
NSString * string = [obj text];\ | |
[formData addObject:[NSString stringWithFormat:@"%@=%@", key, [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];\ | |
}\ | |
else if([obj isKindOfClass:[NSString class]]) {\ | |
[formData addObject:[NSString stringWithFormat:@"%@=%@", key, [obj stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];\ | |
}\ | |
}\ | |
\ | |
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{\ | |
NSString * httpBody = [formData componentsJoinedByString:@"&"];\ | |
NSMutableURLRequest * request = nil \ | |
\ | |
if([FORM[@"method"] isEqualToString:@"GET"]) \ | |
request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:[FORM[@"action"] stringByAppendingFormat:@"?%@", httpBody]]];\ | |
else \ | |
request= [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:FORM[@"action"]]]\ | |
[request setHTTPMethod:FORM[@"method"]];\ | |
[request setHTTPBody:[httpBody dataUsingEncoding:NSUTF8StringEncoding]];\ | |
NSURLResponse * res;\ | |
NSError * error;\ | |
\ | |
id data = [NSURLConnection sendSynchronousRequest:request returningResponse:&res error:&error];\ | |
(BLOCK)(data, res, error);\ | |
});\ | |
}\ | |
#define LVS_SET_FRAME(SELF, X, Y, WIDTH, HEIGHT) SELF.frame = CGRectMake(X, Y, WIDTH, HEIGHT); | |
#define LVS_SET_SIZE(SELF, WIDTH, HEIGHT) SELF.frame = CGRectMake(SELF.frame.origin.x, SELF.frame.origin.y, WIDTH, HEIGHT); | |
#define LVS_SET_ORIGIN(SELF, X, Y) SELF.frame = CGRectMake(X, Y, SELF.frame.size.width, SELF.frame.size.height); | |
#define LVS_SET_ORIGIN_X(SELF, X) SELF.frame = CGRectMake(X, SELF.frame.origin.y, SELF.frame.size.width, SELF.frame.size.height); | |
#define LVS_SET_ORIGIN_Y(SELF, Y) SELF.frame = CGRectMake(SELF.frame.origin.x, Y, SELF.frame.size.width, SELF.frame.size.height); | |
#define LVS_SET_WIDTH(SELF, WIDTH) SELF.frame = CGRectMake(SELF.frame.origin.x, SELF.frame.origin.y, WIDTH, SELF.frame.size.height); | |
#define LVS_SET_HEIGHT(SELF, HEIGHT) SELF.frame = CGRectMake(SELF.frame.origin.x, SELF.frame.origin.y, SELF.frame.size.width, HEIGHT); | |
#define LVS_LEFT_MARGIN_FROM_VIEW(SELF, TARGET, MARGIN) \ | |
SELF.frame = CGRectMake(TARGET.frame.origin.x - SELF.frame.size.width - MARGIN, SELF.frame.origin.y, SELF.frame.size.width, SELF.frame.size.height); | |
#define LVS_RIGHT_MARGIN_FROM_VIEW(SELF, TARGET, MARGIN) \ | |
SELF.frame = CGRectMake(TARGET.frame.size.width + TARGET.frame.origin.x + MARGIN, SELF.frame.origin.y, SELF.frame.size.width, SELF.frame.size.height); | |
#define LVS_TOP_MARGIN_FROM_VIEW(SELF, TARGET, MARGIN) \ | |
SELF.frame = CGRectMake(SELF.frame.origin.x, TARGET.frame.origin.y - SELF.frame.size.height - MARGIN, SELF.frame.size.width, SELF.frame.size.height); | |
#define LVS_BOTTOM_MARGIN_FROM_VIEW(SELF, TARGET, MARGIN) \ | |
SELF.frame = CGRectMake(SELF.frame.origin.x, TARGET.frame.origin.y + TARGET.frame.size.height + MARGIN, SELF.frame.size.width, SELF.frame.size.height); | |
#define LVS_HORIZON_MID_IN_VIEW(SELF, TARGET) \ | |
SELF.frame = CGRectMake((TARGET.frame.size.width - SELF.frame.size.width) / 2, SELF.frame.origin.y, SELF.frame.size.width, SELF.frame.size.height); | |
#define LVS_VERTICAL_MID_IN_VIEW(SELF, TARGET) \ | |
SELF.frame = CGRectMake(SELF.frame.origin.x, (TARGET.frame.size.height - SELF.frame.size.height) / 2, SELF.frame.size.width, SELF.frame.size.height); | |
#define LVS_CENTER_IN_VIEW(SELF, TARGET) \ | |
SELF.frame = CGRectMake((TARGET.frame.size.width - SELF.frame.size.width) / 2, (TARGET.frame.size.height - SELF.frame.size.height) / 2, SELF.frame.size.width, SELF.frame.size.height); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment