Skip to content

Instantly share code, notes, and snippets.

@mayoralito
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayoralito/60ec0cf098a1271b16d4 to your computer and use it in GitHub Desktop.
Save mayoralito/60ec0cf098a1271b16d4 to your computer and use it in GitHub Desktop.
Objective C snippets
// .h file
#import <UIKit/UIKit.h>
@interface AMTextField : UITextField
@property (nonatomic, assign) UIEdgeInsets edgeInsets;
@end
// .m file
#import "AMTextField.h"
@implementation AMTextField
- (id)initWithFrame:(CGRect)frame{
self = [super initWithFrame:frame];
if (self) {
self.edgeInsets = UIEdgeInsetsMake(10, 40, 10, 10);
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder{
self = [super initWithCoder:aDecoder];
if(self){
self.edgeInsets = UIEdgeInsetsMake(10, 40, 10, 10);
}
return self;
}
- (CGRect)textRectForBounds:(CGRect)bounds {
return [super textRectForBounds:UIEdgeInsetsInsetRect(bounds, self.edgeInsets)];
}
- (CGRect)editingRectForBounds:(CGRect)bounds {
return [super editingRectForBounds:UIEdgeInsetsInsetRect(bounds, self.edgeInsets)];
}
@end
// Change general appearance
[[UITextField appearance] setTintColor:[UIColor colorWithHexString:GREEN_COLOR]];
// Change specific element.
[[self.inputTextField valueForKey:@"textInputTraits"] setValue:[UIColor redColor] forKey:@"insertionPointColor"];
/**
Add key NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription
(background GPS use) with string asking to use GPS on each info.plist from each target.
*/
[locationManager startUpdatingLocation];
[locationManager requestWhenInUseAuthorization];
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
}
UIActionSheet *as = [[UIActionSheet alloc] initWithTitle:@"Title of view:"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil otherButtonTitles:nil];
[as addButtonWithTitle:@"Op1"];
[as addButtonWithTitle:@"Op2"];
[as showInView:self.view.window];
// Delegate....
// UIActionSheetDelegate
// - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment