Last active
August 29, 2015 14:14
-
-
Save mayoralito/60ec0cf098a1271b16d4 to your computer and use it in GitHub Desktop.
Objective C snippets
This file contains hidden or 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
// .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 |
This file contains hidden or 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
// Change general appearance | |
[[UITextField appearance] setTintColor:[UIColor colorWithHexString:GREEN_COLOR]]; | |
// Change specific element. | |
[[self.inputTextField valueForKey:@"textInputTraits"] setValue:[UIColor redColor] forKey:@"insertionPointColor"]; |
This file contains hidden or 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
/** | |
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]; | |
} | |
This file contains hidden or 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
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