Skip to content

Instantly share code, notes, and snippets.

View Bayonetta's full-sized avatar
🎯
Focusing

Bayonetta Bayonetta

🎯
Focusing
  • Nomi
View GitHub Profile
@Bayonetta
Bayonetta / contentTypeForImageData.m
Created January 26, 2015 13:09
judge mime type from NSData
- (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:
@Bayonetta
Bayonetta / ButtonUtil.m
Created December 1, 2014 10:21
Use tint color to change image color in uibutton
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *image = [[UIImage imageNamed:@"image_name"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
[button setImage:image forState:UIControlStateNormal];
button.tintColor = [UIColor yourColor];
@Bayonetta
Bayonetta / tips
Created September 4, 2014 14:53
获取View/NSString填充高度
systemLayoutSizeFittingSize:
boundingRectWithSize:options:attributes:context:
@Bayonetta
Bayonetta / viewToImageConverter
Created August 26, 2014 07:23
converter view to image
- (UIImage *)imageFromView:(UIView *)view {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);
[view drawViewHierarchyInRect:view.bounds afterScreenUpdates:NO];
UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
@Bayonetta
Bayonetta / rotationImage
Created August 18, 2014 06:30
rotate image to specified orientation
- (UIImage *)imageRotatedByDegrees:(UIImage*)oldImage deg:(CGFloat)degrees{
//Calculate the size of the rotated view's containing box for our drawing space
UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,oldImage.size.width, oldImage.size.height)];
CGAffineTransform t = CGAffineTransformMakeRotation(degrees * M_PI / 180);
rotatedViewBox.transform = t;
CGSize rotatedSize = rotatedViewBox.frame.size;
//Create the bitmap context
UIGraphicsBeginImageContext(rotatedSize);
CGContextRef bitmap = UIGraphicsGetCurrentContext();
@Bayonetta
Bayonetta / completeVideoHandler
Last active August 29, 2015 14:05
handle video completed
-(void)startPlaybackForItemWithURL:(NSURL*)url {
// First create an AVPlayerItem
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:url];
// Subscribe to the AVPlayerItem's DidPlayToEndTime notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
// Pass the AVPlayerItem to a new player
AVPlayer* player = [[[AVPlayer alloc] initWithPlayerItem:playerItem] autorelease];
@Bayonetta
Bayonetta / AutoAdjuster
Created July 17, 2014 02:45
Auto adjust the height of ViewController in iOS7
/*
iOS7中UIViewController新增的属性extendedLayoutIncludesOpaqueBars和edgesForExtendedLayout可以解决该问题。
其中这个属性指定了当Bar使用了不透明图片时,视图是否延伸至Bar所在区域,默认值时NO。
而edgesForExtendedLayout则是表示视图是否覆盖到四周的区域,默认是UIRectEdgeAll,即上下左右四个方向都会覆盖,
那么为让顶部不进行延伸到导航栏覆盖的区域,我们可以把顶部区域延伸去掉。
*/
self.extendedLayoutIncludesOpaqueBars = NO;
@Bayonetta
Bayonetta / resign.sh
Created May 5, 2014 04:36
ipa resign shell script
#!/bin/sh
if ! ([ -f "$1" ]); then
echo \"${1}\"文件不存在
exit
fi
ipaName=${1%.ipa}
if [ "$ipaName" = "$1" ]; then
echo \"${1}\"不是ipa文件
exit
@Bayonetta
Bayonetta / viewToImageConverter.m
Created April 11, 2014 07:47
view convert to image
- (UIImage*) imageWithUIView:(UIView*) view{
// 创建一个bitmap的context
// 并把它设置成为当前正在使用的context
UIGraphicsBeginImageContext(view.bounds.size);
CGContextRef currnetContext = UIGraphicsGetCurrentContext();
//[view.layer drawInContext:currnetContext];
[view.layer renderInContext:currnetContext];
// 从当前context中创建一个改变大小后的图片
UIImage* image = UIGraphicsGetImageFromCurrentImageContext();
// 使当前的context出堆栈
@Bayonetta
Bayonetta / passThroughView.m
Created March 19, 2014 07:43
Passing through touches to UIViews underneath
UIView *view = [UIView alloc]init];
view.userInteractionEnabled = NO;