Skip to content

Instantly share code, notes, and snippets.

@osmszk
osmszk / button-tapped
Created January 27, 2014 14:10
button-tapped-osuzuki
- (void)viewDidLoad
{
UIButton *stateButton = [UIButton buttonWithType:UIButtonTypeCustom];
stateButton.exclusiveTouch = YES;
stateButton.frame = CGRectMake(10.0f, 180.0f, 300.0f, 46.0f);
stateButton.titleEdgeInsets = UIEdgeInsetsMake(0.0f, -300.0f, 0.0f, 0.0f);
stateButton.titleLabel.font = [UIFont boldSystemFontOfSize:17.0f];
[stateButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[stateButton setImage:[UIImage imageNamed:@"alert_button_gray.png"] forState:UIControlStateNormal];
[stateButton setImage:[UIImage imageNamed:@"alert_button_blue.png"] forState:UIControlStateHighlighted];
@osmszk
osmszk / saveImageFile
Created January 30, 2014 08:58
How to save UIImage as PNG
- (void)saveImageFile
{
NSData *data = UIImagePNGRepresentation(uiimage);
NSString *filePath = [NSString stringWithFormat:@"%@/sample.png" ,[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]];
[data writeToFile:filePath atomically:YES];
}
@osmszk
osmszk / dontUseCookie
Last active August 29, 2015 13:55
No use to cookie and remove cache
- (void)dontUseCookie
{
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
}
- (void)removeCache
{
[[NSURLCache sharedURLCache] removeAllCachedResponses];
}
@osmszk
osmszk / consoleLogFile
Last active August 29, 2015 13:55
Write console log as File output
+ (NSString*)consoleLogFileWithDate
{
NSDateFormatter *inputDateFormatter = [[NSDateFormatter alloc] init];
[inputDateFormatter setDateFormat:@"yyyyMMddHHmmss"];
[inputDateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"US"]];
NSString *dateStr = [inputDateFormatter stringFromDate:[NSDate date]];
return [NSString stringWithFormat:@"console%@.log",dateStr];
}
static FILE *consoleLog;
@osmszk
osmszk / convertToJsonFromDictionary
Created January 31, 2014 06:51
Convert to JSON from NSDictionary
- (void)convertToJsonFromDictionary
{
NSDictionary *paramDic = @{@"flg": @"true",
@"result":[NSNull null]};
NSData *paramData = nil;
if([NSJSONSerialization isValidJSONObject:paramDic]){
paramData = [NSJSONSerialization dataWithJSONObject:paramDic options:NSJSONWritingPrettyPrinted error:nil];
NSLog(@"%@",paramDic);
NSLog(@"%@",[[NSString alloc] initWithData:paramData encoding:NSUTF8StringEncoding]);
}
@osmszk
osmszk / shareImageViaLine
Last active August 29, 2015 13:57
How to share image via LINE
- (void)shareImageViaLine:(UIImage *)image
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
//[pasteboard setData:UIImageJPEGRepresentation(image, 1.0) forPasteboardType:@"public.jpeg"];
//→JPEGではできない模様 PNGならOK。
[pasteboard setData:UIImagePNGRepresentation(image) forPasteboardType:@"public.png"];
//PNGで!!!
NSString *urlString = [NSString stringWithFormat:@"line://msg/image/%@",pasteboard.name];
NSURL *url = [NSURL URLWithString:urlString];
@osmszk
osmszk / shuffleArray
Created March 26, 2014 08:22
How to shuffle array
- (NSArray *)randomShuffle:(NSMutableArray *)array
{
for (NSInteger i=0; i<[array count]; i++) {
int exchagingIndex = arc4random() % [array count];//from 0 to count
[array exchangeObjectAtIndex:i withObjectAtIndex:exchagingIndex];
}
return array;
}
@osmszk
osmszk / animationOnTelop
Created April 2, 2014 14:50
Sliding Animation of UILabel like "Telop" or news texts on Social Game  スライドインするテロップ的なアニメーション
- (void)viewDidLoad
{
_newsLabel.text = @"abcdefgh.......";
[self startSlideNewsAnimation];
}
- (void)startSlideNewsAnimation
{
NSString *news = _newsLabel.text;
@osmszk
osmszk / AddPickerView
Last active August 29, 2015 14:04
addPickerView
BOOL _isShowingPicker;
NSArray *_sizeTexts;
NSInteger _sizeIndex;
@property (strong,nonatomic) UIView *pickerMainView;
@property (strong,nonatomic) UIPickerView *pickerView;
@property (strong,nonatomic) UIBarButtonItem *pickerBarButtonItem;
- (void)initPickerView
{
@osmszk
osmszk / countTextZenkaku
Last active August 29, 2015 14:05
Count text length considering Zenkaku(multibyte character)
//@"あいう":6
//@"abc":3
- (NSInteger)textCountWithString:(NSString *)string
{
return [string lengthOfBytesUsingEncoding:NSShiftJISStringEncoding];
}