Skip to content

Instantly share code, notes, and snippets.

View lamprosg's full-sized avatar

Lampros Giampouras lamprosg

  • Athens, Greece
View GitHub Profile
@lamprosg
lamprosg / iteration.mm
Last active December 15, 2015 04:39
(iOS) Backwards iteration. Check a property of a previous controller in the navigation hierarchy
//Example
//Pop views and return to mapresultsviewcontroller
for(UIViewController *vc in [self.navigationController viewControllers]) {
//MapAreaRsultsViewController is 2 controllers back in the hierarchy
if([vc isMemberOfClass:[MapAreaResultsViewController class]]) {
//Remove record from memory
NSMutableArray *records;
@lamprosg
lamprosg / 1.CustomClass.h
Last active November 14, 2022 02:33
(iOS) Creating custom delegates
//Class will be declared later
@class CustomClass;
//Define the protocol for the delegate
@protocol CustomClassDelegate
@required
//Required methods go here
//If there are optional functions, they go here
@lamprosg
lamprosg / buttonWithLabel.mm
Created March 26, 2013 07:31
(iOS) Example stretching an image
UIView *tmpView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetMaxX(self.tableView.bounds), 265)];
NSString *lbl = L(addPhoto);
CGFloat labelwidth = [lbl sizeWithFont:kAddPhotoBtnFont].width;
FormButtonElement *addPhotoBtn = [[FormButtonElement alloc] initWithFrame:CGRectMake(kLeftRightPadding, 0, labelwidth+kLeftRightPadding*4, 30)];
[addPhotoBtn setTitle:L(addPhoto) forState:UIControlStateNormal];
addPhotoBtn.titleLabel.font = kAddPhotoBtnFont;
@lamprosg
lamprosg / 1.setFlag.mm
Last active April 27, 2022 17:25
(iOS) NSUserDefaults
//Set the (bool) flag
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"logged_in"];
[[NSUserDefaults standardUserDefaults]synchronize];
//Read it
if(![[NSUserDefaults standardUserDefaults] boolForKey:@"logged_in"])
{
[self displayLogin];
} else {
[self displayMainScreen];
@lamprosg
lamprosg / appDelegate.mm
Last active February 11, 2023 08:55
(iOS) Running location updates in the background
-(void) applicationDidEnterBackground:(UIApplication *) application
{
// You will also want to check if the user would like background location
// tracking and check that you are on a device that supports this feature.
// Also you will want to see if location services are enabled at all.
// All this code is stripped back to the bare bones to show the structure
// of what is needed.
[locationManager startMonitoringSignificantLocationChanges];
@lamprosg
lamprosg / 1.setIt.mm
Last active December 16, 2015 01:19
(iOS) Local Notifications
- (IBAction)addNotification:(id)sender {
//Create the localNotification object
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
//Set the date when the alert will be launched using the date adding the time the user selected on the timer
localNotification.fireDate:[NSDate dateWithTimeIntervalSinceNow:[datePicker countDownDuration]];
localNotification.timeZone = [NSTimeZone defaultTimeZone];
//The button's text that launches the application and is shown in the alert
@lamprosg
lamprosg / exampleDelegate.mm
Last active December 16, 2015 02:19
(iOS) Navigation & Tabbar controllers
- (void)customizeAppearance {
// customize the navigation bar
[[UINavigationBar appearance] setTitleTextAttributes:@{UITextAttributeFont : kNavigationBarTitleFont}];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar.png"] forBarMetrics:UIBarMetricsDefault];
// UIBarButtonItem
UIImage *button = [[UIImage imageNamed:@"button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 5, 0, 5)];
[[UIBarButtonItem appearance] setBackgroundImage:button forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTitleTextAttributes:@{UITextAttributeFont:[UIFont fontWithName:@"Verdana" size:0.0]} forState:UIControlStateNormal];
@lamprosg
lamprosg / RightDetailedCell.h
Last active December 16, 2015 03:29
(iOS) Custom Cell - Subclass of UITableViewCell
@interface RightDetailedCell : UITableViewCell
@property (nonatomic, assign) BOOL arrow;
@property (nonatomic, assign) BOOL animated;
@end
@lamprosg
lamprosg / 1.0.Info
Last active December 17, 2015 07:58
(Android) Fragments
Official Info:
http://developer.android.com/guide/components/fragments.html
Same lifecycle methods with the Activity lifecycle methods apply
extends DialogFragment
Displays a floating dialog. Using this class to create a dialog is a good alternative to using the dialog helper methods in the Activity class, because you can incorporate a fragment dialog into the back stack of fragments managed by the activity, allowing the user to return to a dismissed fragment.
extends ListFragment
Displays a list of items that are managed by an adapter (such as a SimpleCursorAdapter), similar to ListActivity. It provides several methods for managing a list view, such as the onListItemClick() callback to handle click events.
@lamprosg
lamprosg / 1.Basics.java
Last active December 17, 2015 08:39
(Android) Basics & snippets
// Set the user interface layout for this Activity (activity_main.xml)
//Usually in the onCreate method
setContentView(R.layout.activity_main);
//R.java file have all the resources IDs provided to resources(drawables, layouts, styles etc)
//Example
R.id.edit_message //id of a layout view in the xml