Skip to content

Instantly share code, notes, and snippets.

@sebk
sebk / Activity.java
Created September 13, 2018 17:32
ActionBar Back Button
public class AktuellesDetail extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_aktuelles_detail);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
@sebk
sebk / Activity.java
Created September 13, 2018 16:19
Android RecyclerView Item Click Listener
private void addClickListener(RecyclerView recyclerView) {
recyclerView.addOnItemTouchListener(new RecycleViewItemListener(getApplicationContext(), recyclerView,
new RecyclerItemListener.RecyclerTouchListener() {
public void onClickItem(View v, int position) {
System.out.println("On Click Item interface");
}
public void onLongClickItem(View v, int position) {
System.out.println("On Long Click Item interface");
}
@sebk
sebk / BL on or off
Last active August 29, 2015 14:23
Bluetooth on/off test
#import "ViewController.h"
@import CoreBluetooth;
@interface ViewController () <CBCentralManagerDelegate>
@property(nonatomic, strong) CBCentralManager *cbManager;
@end
@implementation ViewController
@sebk
sebk / NSBundle+Framework
Created December 4, 2014 19:02
Get correct NSBundle for resource in a Cocoa Touch Framework
@import UIKit;
@interface NSBundle (Framework)
+ (NSBundle*)bundleForFramework;
@end
#import "NSBundle+Framework.h"
@sebk
sebk / ReadVersion
Created July 3, 2014 17:54
Read version infos from Info-plist
- (NSString *)versionText
{
NSString *bundleVersion = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];
NSString *buildNumber = [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleVersionKey];
NSString *versionText;
if (bundleVersion) {
if (buildNumber) {
@sebk
sebk / gitattributes
Created April 3, 2014 06:55
.gitattributes to handle pbxproj
# http://stackoverflow.com/questions/1549578/git-and-pbxproj
# http://stackoverflow.com/a/18275082/470964
*.pbxproj -crlf -diff -merge
#import "UIScrollView+Images.h"
@implementation UIScrollView (Images)
- (void)addImages:(NSArray *)images
{
NSMutableDictionary *viewsDictionary = [NSMutableDictionary dictionary];
NSMutableString *visualFormatString = [NSMutableString stringWithString:@"|"];
NSUInteger index = 0;
for (UIImage *anImage in images) {
@sebk
sebk / childViewController
Last active January 4, 2016 03:28
Add/Remove ChildViewController
//add:
UIViewController *childVC = ...;
[childVC willMoveToParentViewController:self];
[self addChildViewController:childVC];
[self.view addSubview:childVC.view];
//set frame or constraints of childVC.view
[childVC didMoveToParentViewController:self];
//remove:
@sebk
sebk / Autolayout size change
Last active December 27, 2015 04:29
Change the size of a UIView with autolayout programmatically
//_constraintHeight and _constraintWidht are IBOutlet NSLayoutConstraints (from _theView), defined in xib
_constraintHeight.constant = NEW_HEIGHT;
_constraintWidth.constant = NEW_WIDTH;
[_theView setNeedsUpdateConstraints];
[UIView animateWithDuration:((animated) ? ANIMATION_DURATION : 0.0) animations:^{
[_theView layoutIfNeeded];
}];
@sebk
sebk / NSDate+Additions
Created October 26, 2013 10:32
NSDate methods
@interface NSDate (Additions)
-(int)numDaysInMonth;
-(int)firstWeekDayInMonth;
-(NSArray *)weeksOfMonth;
-(NSDate*)offsetDay:(int)days;