Skip to content

Instantly share code, notes, and snippets.

View TomLiu's full-sized avatar

Liu Yi TomLiu

View GitHub Profile
@TomLiu
TomLiu / testURLRequest.m
Created August 25, 2011 07:20
cocoa send request to Google Doc
NSString *postwords = @"test";
NSString *post = [NSString stringWithFormat:@"entry.0.single=%@&pageNumber=0&backupCache=&submit=Submit",postwords];
NSData *postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [post length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:@"https://docs.google.com/spreadsheet/formResponse?formkey=yourformkey;ifq"]];
[request setHTTPMethod:@"POST"];
//
// NSColor+Hex.h
//
// Created by 61 on 2/1/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import <AppKit/AppKit.h>
@interface NSColor (Hex)
[newTaskButton setImage:[NSImage imageNamed:@"top-addtask-ori"]];
[newTaskButton setAlternateImage:[NSImage imageNamed:@"top-addtask-sel"]];
[newTaskButton setFrame:CGRectMake(0, 0, 40, 40)];
[newTaskButton setBordered:NO];
//下面两个属性设置解决了出现白框的问题
[newTaskButton setBezelStyle:NSRegularSquareBezelStyle];
[newTaskButton setButtonType:NSMomentaryChangeButton];
@TomLiu
TomLiu / commonLabel.m
Created February 26, 2012 12:05
Cocoa Label
NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(0, 0, 320, 25)];
[label setEditable:NO];
[label setBordered:NO];
[label setFont:[NSFont systemFontOfSize:17.0]];
[label setBackgroundColor:[NSColor clearColor]];
[label setTextColor:[NSColor blackColor];
[label.cell setLineBreakMode:NSLineBreakByTruncatingTail];
[label setAutoresizingMask:NSViewMaxXMargin|NSViewMaxYMargin|NSViewWidthSizable];
[label setStringValue:@"this is a label"];
@TomLiu
TomLiu / attriLabel.m
Created February 26, 2012 12:15
Cocoa label with underline
NSTextField *label = [[NSTextField alloc] initWithFrame:CGRectMake(0, 0, 320, 25)];
[label setEditable:NO];
[label setBordered:NO];
[label setFont:[NSFont systemFontOfSize:17.0]];
[label setBackgroundColor:[NSColor clearColor]];
[label setTextColor:[NSColor blackColor];
[label.cell setLineBreakMode:NSLineBreakByTruncatingTail];
[label setAutoresizingMask:NSViewMaxXMargin|NSViewMaxYMargin|NSViewWidthSizable];
NSFont *font = [NSFont systemFontOfSize:14.0];
@TomLiu
TomLiu / colorLabel.m
Created February 26, 2012 13:09
Cocoa colorful label
NSTextField *timeLabel = [[NSTextField alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
[timeLabel setAutoresizingMask:NSViewMaxXMargin|NSViewMaxYMargin|NSViewWidthSizable];
[timeLabel setEditable:NO];
[timeLabel setBordered:NO];
[timeLabel setAlignment:NSLeftTextAlignment];
[timeLabel setBackgroundColor:[NSColor clearColor]];
NSString *originString = @"firstsecondthird";
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithString:originString];
[string addAttribute:NSForegroundColorAttributeName value:[NSColor redColor] range:NSMakeRange(0,5)];
[string addAttribute:NSForegroundColorAttributeName value:[NSColor greenColor] range:NSMakeRange(5,6)];
@TomLiu
TomLiu / gist:2858916
Created June 2, 2012 15:52 — forked from feng92f/gist:2849163
google收录的敏感词
@TomLiu
TomLiu / TMCell.m
Created June 13, 2012 12:39
NSCell with checkbox
- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)frame ofView:(NSView *)controlView {
NSRect checkBoxFrame = [self _checkBoxFrameForInteriorFrame:frame];
NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil];
// Delegate hit testing to other cells
if (_checkBoxCell) {
if (NSPointInRect(point, checkBoxFrame)) {
return NSCellHitTrackableArea;
}
NSFont *font = [NSFontsystemFontOfSize:14.0];
NSShadow *textShadow = [[NSShadowalloc] init];
[textShadow setShadowColor:[NSColorcolor whiteColor]];
[textShadow setShadowOffset:CGSizeMake(0, -1.0)];
NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjects:[NSArrayarrayWithObjects:font, textShadow, nil]
forKeys:[NSArrayarrayWithObjects:NSFontAttributeName, NSShadowAttributeName, nil]];
CGSize size = [@"string" sizeWithAttributes:attrsDictionary];
CGFloat width = 100.0;
NSDictionary *attrDic = [NSDictionary dictionaryWithObject:[NSFont systemFontOfSize:14.0] forKey:NSFontAttributeName];
NSSize limit = NSMakeSize(width, (unsigned int)-1);
CGRect frame = [@"this is the test string" boundingRectWithSize:limit options:(NSStringDrawingDisableScreenFontSubstitution | NSStringDrawingUsesLineFragmentOrigin) attributes:attrDic];