Skip to content

Instantly share code, notes, and snippets.

View EvgenyMorozov's full-sized avatar

Evgeny Morozov EvgenyMorozov

View GitHub Profile
@EvgenyMorozov
EvgenyMorozov / NavigationBarButtonItemWithOffset
Created September 1, 2015 07:23
Change default position of navigation bar button item
- (void)createBarButtonItemForNavigationItem:(UINavigationItem *)navigationItem
{
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:<@"icon">] style:UIBarButtonItemStylePlain target:self action:@selector(<selector:>)];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = <-offset>;
navigationItem.leftBarButtonItems = @[ negativeSpacer, buttonItem ];
}
@EvgenyMorozov
EvgenyMorozov / Change status bar color while sidebar is opening
Created August 7, 2015 09:01
Change status bar color while sidebar(SWRevealViewController) is opening
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
UIStatusBarStyle statusBarStyle = (position == FrontViewPositionRight) ? UIStatusBarStyleLightContent : UIStatusBarStyleDefault;
[[UIApplication sharedApplication] setStatusBarStyle:statusBarStyle animated:YES];
}
@EvgenyMorozov
EvgenyMorozov / Hide status bar on sidebar opening
Created August 7, 2015 08:59
Hide/show status bar on sidebar opening (SWRevealViewController)
- (void)revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position
{
if (position == FrontViewPositionRight) {
UIApplication *sharedApplication = [UIApplication sharedApplication];
CGFloat statusBarHeight = CGRectGetHeight([sharedApplication statusBarFrame]);
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];
UINavigationController *frontViewController = (id)revealController.frontViewController;
CGPoint center = frontViewController.navigationBar.center;
@EvgenyMorozov
EvgenyMorozov / OpenAppSettings
Last active August 29, 2015 14:23
Open an application settings.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
@EvgenyMorozov
EvgenyMorozov / Material design view customisation
Created May 29, 2015 15:05
Override layoutSubviews to achieve material design appearance
- (void)layoutSubviews {
[super layoutSubviews];
CGFloat radius = 2.0f;
self.layer.cornerRadius = radius;
self.layer.masksToBounds = NO;
self.layer.shadowColor = [UIColor blackColor].CGColor;
self.layer.shadowOffset = CGSizeMake(0, 3);
self.layer.shadowOpacity = 0.5;
CustomHeaderViewWithAutoLayout *customHeaderView = [[CustomHeaderViewWithAutoLayout alloc] init];
CGFloat fittingSize = [customHeaderView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
CGRect fittingFrame = customHeaderView.frame;
fittingFrame.size = fittingSize;
customHeaderView.frame = fittingFrame;
tableView.tableHeaderView = customHeaderView;
@EvgenyMorozov
EvgenyMorozov / CurrentlyUsingLocale
Created May 7, 2015 12:33
Retrieve the locale that application is currently using (For the case, then the application doesn't support system locale).
NSString *localization = [NSBundle mainBundle].preferredLocalizations.firstObject;
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:localization];
@EvgenyMorozov
EvgenyMorozov / Objective-C.gitignore
Created April 3, 2015 10:58
.gitignore for iOS project with CocoaPods (exclude CocoaPods files from repository).
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
@EvgenyMorozov
EvgenyMorozov / AvailableFonts
Last active August 29, 2015 14:18
Log all available fonts on iOS.
NSMutableString *result = [NSMutableString string];
for (NSString* familyName in [UIFont familyNames]) {
[result appendString:[NSString stringWithFormat:@"\nFontFamily:%@ \nFonts:", familyName]];
NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
[result appendString:[NSString stringWithFormat:@"\n%@", fontNames]];
}
NSLog(@"%@", result);