Skip to content

Instantly share code, notes, and snippets.

View yfujiki's full-sized avatar
💭
Moving around

Yuichi Fujiki yfujiki

💭
Moving around
  • Athlee Ltd
  • Japan
View GitHub Profile
@yfujiki
yfujiki / Play music
Created January 23, 2012 16:20
Play music in iPhone application
NSError * error;
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
if(error)
NSLog(@"Failed to set category to the AVAudioSession : %@", [error localizedDescription]);
NSURL * musicURL = [[NSBundle mainBundle] URLForResource:@"music_file_name" withExtension:@"mp3"];
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:musicURL error:&error];
if(error)
NSLog(@"Failed to play AVAudioSession : %@", [error localizedDescription]);
@yfujiki
yfujiki / Play video
Created January 23, 2012 16:22
Play video in iPhone application
NSURL * url = [[NSBundle mainBundle] URLForResource:@"video_file_name" withExtension:@"mov"];
MPMoviePlayerViewController * vc = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
vc.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self presentMoviePlayerViewControllerAnimated:vc];
@yfujiki
yfujiki / Deep copy
Created January 23, 2012 18:48
Deep mutable copy category method of NSDictionary (ObjC)
- (NSMutableDictionary *) mutableDeepCopy {
NSMutableDictionary * returnDict = [[NSMutableDictionary alloc] initWithCapacity:self.count];
NSArray * keys = [self allKeys];
for(id key in keys) {
id oneValue = [self objectForKey:key];
id oneCopy = nil;
if([oneValue respondsToSelector:@selector(mutableDeepCopy)]) {
oneCopy = [oneValue mutableDeepCopy];
@yfujiki
yfujiki / Document directory
Created February 1, 2012 20:07
Obtain document directory in iOS
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
@yfujiki
yfujiki / Zoom scale
Created February 1, 2012 21:03
Get zoom scale from current map (iOS)
MKZoomScale currentZoomScale = map.bounds.size.width / map.visibleMapRect.size.width;
@yfujiki
yfujiki / AddBorderToUIView
Created April 17, 2012 15:50
Add Border to UIView in iOS
UIView * view = ...
view.layer.borderColor = color.CGColor;
view.layer.borderWidth = width;
@yfujiki
yfujiki / AddCornerRadiusToUIView
Created April 17, 2012 15:51
Add corner radius to UIView in iOS
UIView * view = ...
view.layer.masksToBounds = YES;
view.layer.cornerRadius = width;
@yfujiki
yfujiki / Add padding to UITextField
Created April 23, 2012 11:58
Add padding to UITextField
UIView *paddingView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 5, 20)];
textField.leftView = paddingView;
textField.leftViewMode = UITextFieldViewModeAlways;
@yfujiki
yfujiki / gist:3655637
Created September 6, 2012 12:15
Prevent zoom-out in scroll view to mess up with the view component alignment
- (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView *)view
{
if(scrollView == _scrollView && view == _contentView)
{
// Setting ivars for scrollViewDidZoom
_contentOffsetBeforeZoom = _scrollView.contentOffset;
_scrollViewBoundsBeforeZoom = _scrollView.bounds;
}
}
@yfujiki
yfujiki / DropShadow-iOS
Created September 13, 2012 12:43
Drop shadow on UIView (after iOS3.2)
yourView.layer.shadowColor = [[UIColor blackColor] CGColor];
yourView.layer.shadowOffset = CGSizeMake(10.0f, 10.0f);
yourView.layer.shadowOpacity = 1.0f;
yourView.layer.shadowRadius = 10.0f;