Skip to content

Instantly share code, notes, and snippets.

@interface UILabelStrikethrough : UILabel {
int xOffset;
int yOffset;
int widthOffset;
int stroke;
UIColor* strokeColor;
}
@property (nonatomic) int xOffset;
@property (nonatomic) int yOffset;
@property (nonatomic) int widthOffset;
@hhyyy9
hhyyy9 / gist:4225118
Created December 6, 2012 15:07
ntohs, ntohl, htons,htonl的比较
最近的工作是进行程序由 SUN SPARC 向 Intel X86 移植的工作,多数问题都出现在网络字节序的部分,所以拿出来在这部分工作中使用频率较高的几个接口区分比较下:)
ntohs =net to host short int 16位
htons=host to net short int 16位
ntohl =net to host long int 32位
htonl=host to net long int 32位
@hhyyy9
hhyyy9 / gist:4224875
Created December 6, 2012 14:39
位定义
typedef struct bitS
{
unsigned bit0:1;
unsigned bit1:1;
unsigned bit2:1;
unsigned bit3:1;
unsigned bit4:1;
unsigned bit5:1;
unsigned bit6:1;
unsigned bit7:1;
@hhyyy9
hhyyy9 / gist:3802869
Created September 29, 2012 01:39
当开始输入文字以及完成文字输入时,变换text field的背景。
-(BOOL) textFieldShouldBeginEditing:(UITextField *)textField{
[textField setBackground:[UIImage imageNamed:@"ctext_field_02.png"]];
return YES;
}
-(void) textFieldDidEndEditing:(UITextField *)textField{
[textField setBackground:[UIImage imageNamed:@"ctext_field_01.png"]];
}
@hhyyy9
hhyyy9 / gist:3802858
Created September 29, 2012 01:30
在调用 removeFromSuperview 的时候,当前视图会突然消失,这样显得很不友好。这段代码能够让视图慢慢消失。
//
// UIView+JTRemoveAnimated.h
//
// Created by james on 9/1/11.
// http://ioscodesnippet.tumblr.com/
//
@interface UIView (JTRemoveAnimated)
- (void)removeFromSuperviewAnimated;
@hhyyy9
hhyyy9 / gist:3802855
Created September 29, 2012 01:29
程序内调用本地打电话功能-make a phone call
- (void)makeCall:(NSString *)number
{
NSString *txt = number;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]{4}[-]{0,1}[0-9]{4}?" options:NSRegularExpressionSearch error:nil];
NSTextCheckingResult *result = [regex firstMatchInString:txt options:0 range:NSMakeRange(0, [txt length])];
NSString *cleanedString = [[[txt substringWithRange:[result range]] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:@"0123456789-+()"] invertedSet]] componentsJoinedByString:@""];
NSString *escapedPhoneNumber = [cleanedString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *telURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel://%@", escapedPhoneNumber]];
[[UIApplication sharedApplication] openURL:telURL];
}
@hhyyy9
hhyyy9 / gist:3802852
Created September 29, 2012 01:28
当程序崩溃(Crash)时发出通知
1
2
3
4
5
6
7
8
9
@hhyyy9
hhyyy9 / gist:3802850
Created September 29, 2012 01:26
从URL加载图像
+ (UIImage *) imageFromURLString: (NSString *) urlstring
{
// This call is synchronous and blocking
return [UIImage imageWithData:[NSData
dataWithContentsOfURL:[NSURL URLWithString:urlstring]]];
}
@hhyyy9
hhyyy9 / gist:3802846
Created September 29, 2012 01:26
返回图像的灰度模式
+ (UIImage *) grayscaleImage: (UIImage *) image
{
CGSize size = image.size;
CGRect rect = CGRectMake(0.0f, 0.0f, image.size.width,
image.size.height);
// Create a mono/gray color space
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
CGContextRef context = CGBitmapContextCreate(nil, size.width,
size.height, 8, 0, colorSpace, kCGImageAlphaNone);
CGColorSpaceRelease(colorSpace);
@hhyyy9
hhyyy9 / gist:3802840
Created September 29, 2012 01:24
更改导航条上返回按钮的标题
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] init];
barButtonItem.title = @"buttonName";
self.navigationItem.backBarButtonItem = barButtonItem;
[barButtonItem release]