Skip to content

Instantly share code, notes, and snippets.

@nishitpatel
Last active August 29, 2015 14:25
Show Gist options
  • Save nishitpatel/ba598a7706c8948ae051 to your computer and use it in GitHub Desktop.
Save nishitpatel/ba598a7706c8948ae051 to your computer and use it in GitHub Desktop.
Objectice C common function which used in daily programming.
//Get UIColor from Hex color code
+(UIColor *)colorFromHexString:(NSString *)hexString {
unsigned rgbValue = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexString];
[scanner setScanLocation:1]; // bypass '#' character
[scanner scanHexInt:&rgbValue];
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16)/255.0 green:((rgbValue & 0xFF00) >> 8)/255.0 blue:(rgbValue & 0xFF)/255.0 alpha:1.0];
}
//Set Bottom Border to UITextField
+(void)TextFieldBottomBorder_Action:(BOOL)status TextField:(UITextField*)textField{
CALayer *border = [CALayer layer];
CGFloat borderWidth = 1;
if(status){
border.borderColor = [UIColor redColor].CGColor;
}else{
border.borderColor = [UIColor grayColor].CGColor;
}
border.frame = CGRectMake(0, textField.frame.size.height - borderWidth, textField.frame.size.width, textField.frame.size.height);
border.borderWidth = borderWidth;
[textField.layer addSublayer:border];
textField.layer.masksToBounds = YES;
}
//Show Alert Message
+(void)showAlertTitle:(NSString *)title Message:(NSString *)msg{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:msg
delegate:self
cancelButtonTitle:@"Ok"
otherButtonTitles:nil, nil];
[alertView show];
}
//Show Confirm Alert Message and handel its button click event
+(void)ShowAlertDialogWithDeleteMessage{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil
message:@"Are you sure you want to delete this photo?"
delegate:self cancelButtonTitle:@"NO"
otherButtonTitles:@"YES",nil];
[alert show];
}
//Handel Alert View delegets
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
//Button Index 0 is for cancel button
if (buttonIndex == 0)
{
[alertView dismissWithClickedButtonIndex:1 animated:TRUE];
}
//button index 1 is for YES button
if (buttonIndex == 1)
{
//Perform your code on Yes button click
//Here i am deleting user photo
[self deleteUserPhoto];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment