Skip to content

Instantly share code, notes, and snippets.

@pyanfield
pyanfield / Adjust Top Space.m
Created March 26, 2014 06:17
动态调整Top Space
/*
在nib文件中设置autolayout,设置 parentView 和 childView 之间的 top space,然后根据横竖屏来调整 top space大小
*/
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if(UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){
[self adjustTopSpace:100.0f];
}else{
[self adjustTopSpace:300.0f];
@pyanfield
pyanfield / Image UIBarButtonItem.m
Created March 20, 2014 03:40
display original image on UIBarButtonItem
// ios 7 or later
UIImage *icon = [[UIImage imageNamed:@"icon"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIBarButtonItem *iconItem = [[UIBarButtonItem alloc] initWithImage:icon style:UIBarButtonItemStylePlain target:self action:@selector(iconEvent)];
// before ios 6
UIImage *icon = [UIImage imageNamed:@"icon"];
UIButton *iconBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[iconBtn addTarget:self action:@selector(iconEvent) forControlEvents:UIControlEventTouchUpInside];
iconBtn.bounds = CGRectMake( 0, 0, icon.size.width, icon.size.height );
[iconBtn setImage:icon forState:UIControlStateNormal];
@pyanfield
pyanfield / mac tools.md
Last active August 29, 2015 13:57
tools on mac

Mac软件


homebrew-cask

cask是基于homebrew的扩展命令,直接通过命令行去安装Mac的各种软件。免去之前通过下载链接下载DMG文件,然后拖动到Applitions目录,这种手动的安装方法。如果配置一部新的Mac机器,主要安装了cask,通过一个脚本就安装把用到软件一一安装上去,可以节约很多时间。

安装homebrew-cask之前要先安装一下几个软件:
  • Command Line Tools
  • homebrew
@pyanfield
pyanfield / plugins for xcode.md
Last active August 29, 2015 13:57
plugins for xcode
Alcatraz The package manager for Xcode.
https://github.com/supermarin/Alcatraz
curl -fsSL https://raw.github.com/supermarin/Alcatraz/master/Scripts/install.sh | sh
FuzzyAutocompletePlugin A Xcode 5 plugin that adds more flexible autocompletion rather than just prefix-matching.
KSImageNamed-Xcode Xcode plug-in that provides autocomplete for imageNamed: calls.
SCXcodeMiniMap is a plugin that adds a source editor MiniMap to Xcode.
@pyanfield
pyanfield / resolve a conflict between tap gesture with table view didselected event.m
Last active September 14, 2018 08:36
resolve a conflict between tap gesture with table view didselected event
- (BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if ([gestureRecognizer isEqual:self.tapRecognizer]) {
// for ios 7 , need to compare with UITableViewCellContentView
if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"] || [touch.view.superview isKindOfClass:[UITableViewCell class]]) {
return FALSE;
}
}
return TRUE;
}
@pyanfield
pyanfield / compare the current ios version with special one.h
Last active August 29, 2015 13:57
compare the current ios version with special one.
// information comes from http://stackoverflow.com/questions/3339722/how-to-check-ios-version
//-------------------------------------
// you can use this in your code
if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) {
// Load resources for iOS 6.1 or earlier
} else {
// Load resources for iOS 7 or later
}
@pyanfield
pyanfield / check the image's type, jpeg or png.m
Last active December 31, 2015 22:08
check the image's type, jpeg or png
-(BOOL)dataIsValidJPEG:(NSData *)data
{
if (!data || data.length < 2) return NO;
NSInteger totalBytes = data.length;
const char *bytes = (const char*)[data bytes];
return (bytes[0] == (char)0xff &&
bytes[1] == (char)0xd8 &&
bytes[totalBytes-2] == (char)0xff &&
@pyanfield
pyanfield / get file from web and save on the disk.m
Last active December 31, 2015 19:39
[ios] get file from web and save on the disk
// src : file's url
// file : file's name on the disk
// return : file's path on the disk
- (NSString*)catchFileFrom:(NSString*)src toFile:(NSString*)file
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [NSString stringWithFormat:@"%@/%@", [paths objectAtIndex:0],file];
NSURL *url = [NSURL URLWithString:src];
@pyanfield
pyanfield / display the contact list like default phone book.m
Last active December 10, 2015 23:19
display the contact list as default phone book.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Contact* contact = [self.contacts objectAtIndex:indexPath.row];
UITableViewCell *cell = nil;
static NSString *cellId = @"Cell";
cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId] autorelease];
}
UILabel *firstLabel = [[UILabel alloc] initWithFrame:CGRectZero];
@pyanfield
pyanfield / Get your cookies on iOS.m
Last active October 13, 2015 06:27
Get your cookies on iOS
NSArray *array = [[NSHTTPCookieStoragesharedHTTPCookieStorage] cookiesForURL:[NSURLURLWithString:HOST]];
for (NSHTTPCookie *cookie in array) {
for (NSString *key in cookie.properties) {
Logger(@">>>>> cookie key : %@, >>>>>> %@",key,cookie.properties[key]);
}
}