Skip to content

Instantly share code, notes, and snippets.

View mlabraca's full-sized avatar

Miguel Angel Labraca mlabraca

  • The Knot WorldWide
  • Spain
View GitHub Profile
@mlabraca
mlabraca / AttributedString.m
Created July 24, 2015 09:05
Returns an attributed string from value, custom gliph and given font
+ (NSMutableAttributedString *) getAttributtedStringFromValue:(NSString *)value andGliph:(NSString *)gliph forCustomFont:(NSString *)customFont
{
float fontSizeGliph = 25;
float fontSize = 20;
NSString *titleText = [NSString stringWithFormat:@"%@ %@", value, gliph];
UIFont *gliphFont = [UIFont fontWithName:customFont size:fontSizeGliph];
UIFont *defaultFont = [UIFont systemFontOfSize:fontSize];
@mlabraca
mlabraca / AutoCellHeight.swift
Created July 23, 2015 10:08
Automatic row height cell for iOS 8 (Swift)
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.estimatedRowHeight = 80
self.tableView.rowHeight = UITableViewAutomaticDimension
}
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
@mlabraca
mlabraca / ShadowyUILabel
Created February 3, 2015 09:56
Adds shadow to UILabel using NSMutableAttributedString
- (void) addShadowToTextForLabel:(UILabel *)label withColor:(UIColor *)shadowColor andBlurRadius:(CGFloat)blurRadius
{
NSMutableAttributedString* attString = [[NSMutableAttributedString alloc] initWithString:label.text];
NSRange range = NSMakeRange(0, [attString length]);
[attString addAttribute:NSFontAttributeName value:label.font range:range];
[attString addAttribute:NSForegroundColorAttributeName value:label.textColor range:range];
NSShadow* shadow = [[NSShadow alloc] init];
shadow.shadowColor = shadowColor;
shadow.shadowOffset = CGSizeMake(0.0f, 0.0f);
shadow.shadowBlurRadius = blurRadius;
@mlabraca
mlabraca / StatusBar alpha(unsafe)
Created October 28, 2014 09:55
Applies alpha to status bar, but using private methods that would make app been rejected.
- (void) hideStatusbar:(BOOL)mustHide
{
UIView *statusBarView = [[UIApplication sharedApplication] valueForKey:[@[@"status", @"Bar"] componentsJoinedByString:@""]];
statusBarView.alpha = mustHide ? 0 : 1;
}
- (void) startShake:(UIView*)view
{
CGAffineTransform leftShake = CGAffineTransformMakeTranslation(-5, 0);
CGAffineTransform rightShake = CGAffineTransformMakeTranslation(5, 0);
view.transform = leftShake; // starting point
[UIView beginAnimations:@"shake_view" context:view];
[UIView setAnimationRepeatAutoreverses:YES]; // important
[UIView setAnimationRepeatCount:5];
@mlabraca
mlabraca / StatusBar Background
Created October 22, 2014 11:34
Add background to StatusBar in AppDelegate didFinishLaunchingWithOptions
//Create the background
UIView* statusBg = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width, 20)];
//statusBg.backgroundColor = [UIColor colorWithWhite:1 alpha:.7];
statusBg.backgroundColor = [UIColor whiteColor];
//Add the view behind the status bar
[self.window.rootViewController.view addSubview:statusBg];
//set the constraints to auto-resize
statusBg.translatesAutoresizingMaskIntoConstraints = NO;
@mlabraca
mlabraca / animation slide up - slide down
Last active August 29, 2015 14:06
animations: show and remove views with animation
//Showing view from bottom of the paren view (navigationController.view)
+ (void) showView:(UIView *)childView inParentView:(UIView *)parentView withTag:(int)tag
{
float animationTime = 0.3;
CGRect frame = CGRectMake(parentView.frame.origin.x, parentView.frame.size.height, childView.frame.size.width, childView.frame.size.height);
childView.tag = tag;
[parentView addSubview:childView];
[UIView transitionWithView:childView duration:animationTime options:UIViewAnimationOptionCurveEaseInOut animations:^{
[childView setFrame:CGRectMake(frame.origin.x, parentView.frame.size.height - childView.frame.size.height, frame.size.width, frame.size.height)];
} completion:nil];
popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.001, 0.001);
[self.view addSubview:popUp];
[UIView animateWithDuration:0.3/1.5 animations:^{
popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.1, 1.1);
} completion:^(BOOL finished) {
[UIView animateWithDuration:0.3/2 animations:^{
popUp.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.9, 0.9);
} completion:^(BOOL finished) {
@mlabraca
mlabraca / applyMotionEffects:forMotionEffectExtent
Created July 25, 2014 15:23
UIInterpolatingMotionEffect vertically and horizontally for a view (iOS 7 and later)
+ (void) applyMotionEffects:(UIView *)view forMotionEffectExtent:(float)motionEffectExtentOffset
{
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
return;
}
UIInterpolatingMotionEffect *horizontalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x"
type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis];
horizontalEffect.minimumRelativeValue = @(-motionEffectExtentOffset);
horizontalEffect.maximumRelativeValue = @( motionEffectExtentOffset);
UIInterpolatingMotionEffect *verticalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y"
@mlabraca
mlabraca / moveViewHorizontally:duration:forOffset
Created July 25, 2014 15:17
For a given view, applies horizontal movement for offset and duration.
- (void) moveViewHorizontally:(UIView *)view duration:(float)duration forOffset:(float)offset
{
[UIView animateWithDuration:duration
delay:0.0
options: UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
animations:^{
view.center = CGPointMake(view.center.x + offset, view.center.y);
}
completion:NULL];
}