Skip to content

Instantly share code, notes, and snippets.

@hhyyy9
hhyyy9 / MyAVController.m
Created December 28, 2011 08:52 — forked from benlodotcom/MyAVController.h
A little demo snippet that you can use to access directly the camera video in IOS4
#import "MyAVController.h"
@implementation MyAVController
@synthesize captureSession = _captureSession;
@synthesize imageView = _imageView;
@synthesize customLayer = _customLayer;
@synthesize prevLayer = _prevLayer;
@hhyyy9
hhyyy9 / gist:3802827
Created September 29, 2012 01:20
禁止UIWebView下拉拖动效果
//Before iOS 5
for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
//After iOS 5
webView.scrollView.bounces = NO;
@hhyyy9
hhyyy9 / gist:3802829
Created September 29, 2012 01:20
如何判断设备处于静音模式
-(BOOL)silenced
{
#if TARGET_IPHONE_SIMULATOR
// return NO in simulator. Code causes crashes for some reason.
return NO;
#endif
CFStringRef state;
UInt32 propertySize = sizeof(CFStringRef);
AudioSessionInitialize(NULL, NULL, NULL, NULL);
@hhyyy9
hhyyy9 / gist:3802833
Created September 29, 2012 01:23
利用正则表达式判断手机号码格式是否合法
- (BOOL)isMobileNumber:(NSString *)mobileNum
{
/**
* 手机号码
* 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
* 联通:130,131,132,152,155,156,185,186
* 电信:133,1349,153,180,189
*/
NSString * MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
/**
@hhyyy9
hhyyy9 / gist:3802834
Created September 29, 2012 01:23
文字描边可以达到文字描一圈白边的效果
//继承UILabel以后重载drawTextInRect
- (void)drawTextInRect:(CGRect)rect {
CGSize shadowOffset = self.shadowOffset;
UIColor *textColor = self.textColor;
CGContextRef c = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(c, 1);
CGContextSetLineJoin(c, kCGLineJoinRound);
@hhyyy9
hhyyy9 / gist:3802835
Created September 29, 2012 01:24
根据要显示的文字以及UILable本身的字体,来计算能够完全显示所有文字的label所需要的大小,从而进行调整。
//Calculate the size necessary for the UILable
NSString *theText = @"Texting";
CGSize theStringSize = [theText sizeWithFont:font
constrainedToSize:theLabel.frame.size
lineBreakMode:theLabel.lineBreakMode];
//Adjust the size of the UILable
theLable.frame = CGRectMake(theLable.frame.origin.x,
theLable.frame.origin.y,
theStringSize.width, theStringSize.height);
@hhyyy9
hhyyy9 / gist:3802840
Created September 29, 2012 01:24
更改导航条上返回按钮的标题
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] init];
barButtonItem.title = @"buttonName";
self.navigationItem.backBarButtonItem = barButtonItem;
[barButtonItem release]
@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: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:3802852
Created September 29, 2012 01:28
当程序崩溃(Crash)时发出通知
1
2
3
4
5
6
7
8
9