Category Archives: IOS

「mac」tomcat起動スクリプトを設定するメモ

$sudo chmod +x /usr/local/tomcat/bin/*.sh
$vi /usr/local/bin/tomcat
#!/bin/bash
case $1 in
start)
sh /usr/local/etc/tomcat/tomcat/bin/startup.sh
;;
stop)
sh /usr/local/etc/tomcat/tomcat/bin/shutdown.sh
;;
restart)
sh /usr/local/etc/tomcat/tomcat/bin/shutdown.sh
sh /usr/local/etc/tomcat/tomcat/bin/startup.sh
;;
*)
echo “Usage: start|stop|restart”
;;
esac

exit 0
$tomcat start
$tomcat stop
$tomcat restart

「ios開発」経過時間差を計算するコード

iosコード
-(BOOL)HanOrderTimer{
userdefault = NSUserDefault;
if ([userdefault objectForKey:@”LoginTime”]) {
//日付フォーマット
NSDateFormatter *cftFormatter = [[NSDateFormatter alloc]init];
[cftFormatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”];
//ログイン時間文字列
NSString *orderedTime = [userdefault valueForKey:@”LoginTime”];
//ログイン時間
NSDate *orderedDate = [cftFormatter dateFromString:orderedTime];
NSTimeZone *zone1 = [NSTimeZone systemTimeZone];
NSInteger interval1 = [zone1 secondsFromGMTForDate:orderedDate];
NSDate *localDate1 = [orderedDate dateByAddingTimeInterval:interval1];

//現在時刻
NSDate *currentDate = [NSDate date];
NSTimeZone *zone2 = [NSTimeZone systemTimeZone];
NSInteger interval2 = [zone2 secondsFromGMTForDate:currentDate];
NSDate *localDate2 = [currentDate dateByAddingTimeInterval:interval2];
double intervalTime = [localDate2 timeIntervalSinceReferenceDate] – [localDate1 timeIntervalSinceReferenceDate];
int iTime = (int)intervalTime;
if (iTime>=900)
return YES;
}else{
return NO;
};
}else{
return NO;
}
}

「iOS開発」画像をダブルタップで拡大・縮小するサンプルコード

サンプルコード
1.demo.h
#import
@interface ZoomImage : NSObject
+(void)showImage:(UIImageView*)avatarImageView;
@end

2.demo.m
#import “ZoomImage.h”
static CGRect oldframe;
@implementation ZoomImage
+(void)showImage:(UIImageView*)avatarImageView
{
UIImage *image =avatarImageView.image;
// windowを取得
UIWindow *window =[UIApplication sharedApplication].keyWindow;
UIView *backgroundView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
oldframe =[avatarImageView convertRect:avatarImageView.bounds toView:window];
backgroundView.backgroundColor =[UIColor blackColor];
backgroundView.alpha =0.5;
UIImageView *imageView =[[UIImageView alloc]initWithFrame:oldframe];
imageView.image =image;
imageView.tag =1;
[backgroundView addSubview:imageView];
[window addSubview:backgroundView];
//縮小
UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hideImage:)];
[backgroundView addGestureRecognizer:tap];
[UIView animateWithDuration:0.3 animations:^{
imageView.frame =CGRectMake(0,([UIScreen mainScreen].bounds.size.height-image.size.height*[UIScreen mainScreen].bounds.size.width/image.size.width)/2, [UIScreen mainScreen].bounds.size.width, image.size.height*[UIScreen mainScreen].bounds.size.width/image.size.width);
backgroundView.alpha =1;
}];
}
+(void)hideImage:(UITapGestureRecognizer *)tap{
UIView *backgroundView =tap.view;
UIImageView *imageView =(UIImageView *)[tap.view viewWithTag:1];
[UIView animateWithDuration:0.3 animations:^{
imageView.frame =oldframe;
backgroundView.alpha =0;
} completion:^(BOOL finished) {
[backgroundView removeFromSuperview];
}];
}

「iOS開発」文字列操作方法まとめ(例componentsSeparatedByString()、stringrangeOfString())

NSString *cftAA = @”234″;
NSString *cftBB = @”678″;
1.文字列連結
NSString *newString = [NSString stringWithFormat:@”%@%@”,cftAA,cftBB];

2.文字列->int
int intString = [newString intValue];

3.int->文字列
NSString *stringInt = [NSString stringWithFormat:@”%d”,intString];

4.文字列->float
float floatString = [newString floatValue];
5.float->文字列
NSString *stringFloat = [NSString stringWithFormat:@”%f”,intString];

6.文字列分割
SString*string =@”startnews24 change”;
string = [string substringToIndex:7];
NSLog(@”substring value :%@”,string);
[string substringFromIndex:2];
NSLog(@”substring value :%@”,string);

7.stringrangeOfString()正規表現
NSString*string =@”startnews24 pchange”;
NSRangerange = [stringrangeOfString:@”f”];
NSLog(@”rang:%@”,NSStringFromRange(range));
string = [string substringWithRange:range];
NSLog(@”after value:%@”,string);

8.componentsSeparatedByString()文字列分割
NSString*string =@”sdfsfsfsAdfsdf”;
NSArray *array = [string componentsSeparatedByString:@”A”];
NSLog(@”array:%@”,array);

「iOS入門」NSStringのtrimming関数を利用するコード

サンプルコード
– (BOOL)isPureNumandCharacters:(NSString *)string
{
string = [string stringByTrimmingCharactersInSet;[NSCharacterSet decimalDigitCharacterSet]];
if(string.length > 0)
{
return NO;
}
return YES;
}

「iOS開発」NSScannerで整数値かどうか調べるコード

1.整数
– (BOOL)isPureInt:(NSString *)string{
NSScanner* scan = [NSScanner scannerWithString:string];
int val;
return [scan scanInt:&val] && [scan isAtEnd];
}
2.Float
– (BOOL)isPureInt:(NSString *)string{
NSScanner* scan = [NSScanner scannerWithString:string];
int val;
return [scan scanInt:&val] && [scan isAtEnd];
}

「ios開発」デバイスとアプリに関する情報を取得サンプル

サンプルコード:

//デバイスに関する情報
NSString *strName = [[UIDevice currentDevice] name];
NSLog(@”デバイス名:%@”, strName);
NSString *strId = [[UIDevice currentDevice] uniqueIdentifier];

NSString *strSysName = [[UIDevice currentDevice] systemName];
NSLog(@”システム名:%@”, strSysName);// e.g. @”iOS”
NSString *strSysVersion = [[UIDevice currentDevice] systemVersion];
NSLog(@”システムバージョン:%@”, strSysVersion);// e.g. @”6.0″
NSString *strModel = [[UIDevice currentDevice] model];
NSLog(@”デバイスモード:%@”, strModel);// e.g. @”iPhone”, @”iPod touch”
NSString *strLocModel = [[UIDevice currentDevice] localizedModel];
NSLog(@”ローカルデバイスモード:%@”, strLocModel);// localized version of model

//appに関する情報
NSDictionary *dicInfo = [[NSBundle mainBundle] infoDictionary];

// CFShow(dicInfo);
NSString *strAppName = [dicInfo objectForKey:@”CFBundleDisplayName”];
NSLog(@”App名:%@”, strAppName);
NSString *strAppVersion = [dicInfo objectForKey:@”CFBundleShortVersionString”];
NSLog(@”Appバージョン:%@”, strAppVersion);
NSString *strAppBuild = [dicInfo objectForKey:@”CFBundleVersion”];
NSLog(@”AppのBuildバージョン:%@”, strAppBuild);

//ユーザーの言語を取得する
NSArray *languageArray = [NSLocale preferredLanguages];
NSString *language = [languageArray objectAtIndex:0];
NSLog(@”言語:%@”, language);//en
NSLocale *locale = [NSLocale currentLocale];
NSString *country = [locale localeIdentifier];
NSLog(@”国:%@”, country); //en_US

//画面サイズ
CGRect rect = [[UIScreen mainScreen] bounds];
CGSize size = rect.size;
CGFloat width = size.width;
CGFloat height = size.height;
NSLog(@”幅、高:%f,%f”,width,height);

//解像度
CGFloat scale_screen = [UIScreen mainScreen].scale;
NSLog(@”screen w:%f”,width*scale_screen);
NSLog(@”screen h:%f”,height*scale_screen);

「iOS入門」Core Dataの使い方

コード:
1.contextを取得
– (NSManagedObjectContext *)managedObjectContext {
NSManagedObjectContext *context = nil;
id delegate = [[UIApplication sharedApplication] delegate];
if ([delegate performSelector:@selector(managedObjectContext)]) {
context = [delegate managedObjectContext];
}
return context;
}
2.データを追加
NSManagedObjectContext *context = [self managedObjectContext];

// Create a new managed object
NSManagedObject *newDevice = [NSEntityDescription insertNewObjectForEntityForName:@”Device” inManagedObjectContext:context];
[newDevice setValue:self.nameTextField.text forKey:@”name”];
[newDevice setValue:self.versionTextField.text forKey:@”version”];
[newDevice setValue:self.companyTextField.text forKey:@”company”];

NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@”Can’t Save! %@ %@”, error, [error localizedDescription]);
}

3.データを削除
NSManagedObjectContext *context = [self managedObjectContext];

// Delete object from database
[context deleteObject:[self.devices objectAtIndex:indexPath.row]];

NSError *error = nil;
if (![context save:&error]) {
NSLog(@”Can’t Delete! %@ %@”, error, [error localizedDescription]);
return;
}

4.データを修正
NSManagedObjectContext *context = [self managedObjectContext];

// Update existing device
[self.device setValue:self.nameTextField.text forKey:@”name”];
[self.device setValue:self.versionTextField.text forKey:@”version”];
[self.device setValue:self.companyTextField.text forKey:@”company”];
NSError *error = nil;
// Save the object to persistent store
if (![context save:&error]) {
NSLog(@”Can’t Save! %@ %@”, error, [error localizedDescription]);
}
5. データを検索
// Fetch the devices from persistent data store
NSManagedObjectContext *managedObjectContext = [self managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@”Device”];
self.devices = [[managedObjectContext executeFetchRequest:fetchRequest error:nil] mutableCopy];

詳細内容 http://www.appcoda.com/introduction-to-core-data/

ios開発–画面のスクロールを管理するクラスUIScrollView

1.プロパティ紹介
CGFloat screenW = [UIScreen mainScreen].bounds.size.width;
CGFloat screenH = [UIScreen mainScreen].bounds.size.height;
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, screenW,screenH)];
//CGSize
scrollView.contentSize = CGSizeMake(screenW,screenH);
//CGPoint
scrollView.contentOffset = CGPointMake(100, 100);
//UIEdgeInsets
scrollView.contentInset = UIEdgeInsetsMake(0, 0, 20, 20);
//BOOL
scrollView.bounces = NO;
//BOOL
scrollView.scrollEnabled = NO;
//BOOL
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.showsVerticalScrollIndicator = NO;
2.サンプルコード
UIScrollView *sv = [[UIScrollView alloc] initWithFrame:self.view.bounds];
sv.backgroundColor = [UIColor cyanColor];

UIView *uv = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1000, 1000)];
[sv addSubview:uv];
sv.contentSize = uv.bounds.size;
[self.view addSubview:sv];

CentOSでファイルを圧縮、解凍する

1.tarファイルをアーカイブ
#tar cvf sample.tar file1 file2

ディレクトリをアーカイブ
#tar cvf sample.tar dir1 dir2

tarファイルを展開
#tar xvf xxx.tar
2.gzファイルを圧縮
# gzip -v file1 file2

ディレクトリを圧縮
# gzip -rv dir1 dir2
3.lzhファイル
lzhファイルを圧縮
#lha -c sample.lzh file1 file2

ディレクトリを圧縮
#lha -c sample.lzh dir1 dir2

2 / 2212345...1020...最後 »