Skip to content

Instantly share code, notes, and snippets.

@ruandao
ruandao / DirectionPanGestureRecognizer.h
Last active August 29, 2015 14:02
DirectionPanGestureRecognizer 专门识别竖向或者横向的拖动
#import <UIKit/UIKit.h>
#import <UIKit/UIGestureRecognizerSubclass.h>
typedef enum {
DirectionPangestureRecognizerVertical,
DirectionPanGestureRecognizerHorizontal
} DirectionPangestureRecognizerDirection;
@interface DirectionPanGestureRecognizer : UIPanGestureRecognizer
@ruandao
ruandao / UIScrollView+zoomToCenterWithScaleAnimated.h
Created June 22, 2014 15:13
UIScrollView+zoomToCenterWithScaleAnimated
//
// UIScrollView+zoomToCenterWithScale.h
// locationme
//
// Created by 金燕赖 on 14-6-22.
// Copyright (c) 2014年 ljy. All rights reserved.
//
#import <UIKit/UIKit.h>
@ruandao
ruandao / p.m
Created July 14, 2014 05:56
core text attribute string miss last line fix
- (NSMutableAttributedString*)fixLastLineMissBugWhenDrawWithCoreText:(NSMutableAttributedString*)content
{
//段落
//line break
CTParagraphStyleSetting lineBreakMode;
CTLineBreakMode lineBreak = kCTLineBreakByCharWrapping; //换行模式
lineBreakMode.spec = kCTParagraphStyleSpecifierLineBreakMode;
lineBreakMode.value = &lineBreak;
lineBreakMode.valueSize = sizeof(CTLineBreakMode);
@ruandao
ruandao / inputFrameAnimationWithKeyboard.m
Last active August 29, 2015 14:04
键盘出现消失相关代码 让输入框随键盘飘动,点击页面空白地方,让键盘消失
@interface ViewController ()
@property (nonatomic) UITextView *textField;
@property (nonatomic) UIView *textFieldContainer;
@end
@implementation ViewController
- (void)viewDidLoad {
@ruandao
ruandao / gist:8021b4e6683c5f564300
Created July 29, 2014 03:07
mfmessage send message
- (void)showEmail:(NSString*)file {
NSString *emailTitle = @"Great Photo and Doc";
NSString *messageBody = @"Hey, check this out!";
NSArray *toRecipents = [NSArray arrayWithObject:@"support@appcoda.com"];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:emailTitle];
[mc setMessageBody:messageBody isHTML:NO];
@ruandao
ruandao / gist:ee3f6e014fe9ffa61aee
Last active August 29, 2015 14:04 — forked from hebertialmeida/gist:9234391
iOS resize view to fit subviews
- (void)resizeToFitSubviews:(UIView *)view
{
float w, h;
for (UIView *v in view.subviews) {
float fw = v.frame.origin.x + v.frame.size.width;
float fh = v.frame.origin.y + v.frame.size.height;
w = MAX(fw, w);
h = MAX(fh, h);
}
@ruandao
ruandao / gist:db8691f86d87fa97b0a8
Last active August 29, 2015 14:04
mime type of nsdata of image
+ (NSString *)contentTypeForImageData:(NSData *)data {
uint8_t c;
[data getBytes:&c length:1];
switch (c) {
case 0xFF:
return @"image/jpeg";
case 0x89:
return @"image/png";
case 0x47:
@ruandao
ruandao / gist:65198fb651f28bd6bf84
Created August 2, 2014 14:26
ios 动态参数例子
+ (NSString *)downloadUrlWithUserEmail:(NSString *)email, ... {
NSMutableArray *argsArr = [@[] mutableCopy];
va_list params;
va_start(params, email);
id arg;
if (email) {
@ruandao
ruandao / gist:135532b94b53f9b882db
Created September 26, 2014 08:29
让tableview 不自动设置 contentinset
self.title = LocStr(@"本地");
self.automaticallyAdjustsScrollViewInsets = YES;
self.edgesForExtendedLayout = UIRectEdgeNone;
@ruandao
ruandao / Prefix.h
Created October 16, 2014 09:05
Prefix.h
#ifndef yahame_Prefix_h
#define yahame_Prefix_h
#if !defined(DEBUG)
//#define NSLog(...) ;
#endif
#define NS_USERDEFAULT [NSUserDefaults standardUserDefaults]