Category Archives: IOS

「ios開発」plistファイルの読み込む方法

サンプルコード:
NSString *path = [[NSBundle mainBundle] pathForResource:@”filename_startnews24″ ofType:@”plist”];
// file data type array
NSArray *array=[NSArray arrayWithContentsOfFile:path];
//file data type *dictionary
NSDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:path];

ASIHTTPRequestでhttpsにアクセスする方法

方法1
ASIHTTPRequest *request = [ASIHTTPRequestrequestWithURL:[NSURLURLWithString:bodyString]];

[request setDelegate:self];

request.timeOutSeconds = 20;

[request setRequestMethod:@”POST”];

[request addRequestHeader:@”Content-Type”value:@”application/xml;charset=UTF-8;”];

[request setValidatesSecureCertificate:NO];//httpsにアクセス

[request startAsynchronous];

方法2

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:bodyString]];
[request setDelegate:self];
request.timeOutSeconds = 20;
[request setValidatesSecureCertificate:NO];
[request setRequestMethod:@”POST”]; [request addRequestHeader:@”Content-Type” value:@”application/xml;charset=UTF-8″]; request.defaultResponseEncoding = NSUTF8StringEncoding;

「Objective-C」ios開発でNavigationBarを透明にする方法のまとめ

方法1
if ([self.navigationController.navigationBarrespondsToSelector:@selector( setBackgroundImage:forBarMetrics:)]){
NSArray *list = self.navigationController.navigationBar.subviews;
for (id objin list) {
if ([obj isKindOfClass:[UIImageViewclass]]) {
UIImageView *imageView = (UIImageView *)obj;
imageView.hidden = YES;
}
}
}

方法2
[self.navigationController.navigationBar setShadowImage:[UIImage new]];

「Objective-C」ios開発でLableの長さによってimageViewの長さを伸びる方法

処理コード:
_reserveLabel.text = @”welcome to arkgame.com”;
//Labelのコンテンツ長さを取得
CGSize reserveLabelSize = [_reserveLabel sizeThatFits:CGSizeMake(MAXFLOAT, 32)];

//Lableのframeをリセット
_reserveLabel.frame = CGRectMake(10, 0, reserveLabelSize.width, 32);

//imageに背景画像を置く
UIImage *image = [UIImage imageNamed:@”biao1″];

//ストレッチ位置を選択
image = [image stretchableImageWithLeftCapWidth:(2) topCapHeight:(0)];

//imageViewのframeをリセット
_reserveImageView.frame = CGRectMake(0, cookImageViewH – 17 – 32, _reserveLabel.width + 20, 32);

//imageViewのimageを設定
_reserveImageView.image = image;

「Objective-C」ios開発でtextFieldの値変更をリアルタイムリスナーする方法

参考ソースコード:
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:
@selector(infoAction)name:UITextFieldTextDidChangeNotificationobject:nil];
– (void)infoAction
{
NSIndexPath *index = [NSIndexPathindexPathForRow:0inSection:1];
OrderConfirmInfoTableViewCell *cell = (OrderConfirmInfoTableViewCell *)[_tableViewcellForRowAtIndexPath:index];
_phoneStr = cell.phoneField.text;
_addrStr = cell.addressField.text;
}

「Objective-C」日付を操作する方法のまとめ

//現在の日付
NSDate *today = [NSDate date];

//タイムゾーン
NSTimeZone *zone = [NSTimeZone systemTimeZone];

//間隔を設定
_interval = [zone secondsFromGMTForDate: today];

//明日の日付を取得
NSDate *tomorrowDate = [[NSDate alloc]initWithTimeInterval:24 * 60 * 60 sinceDate:[NSDate date]];

//カレンダー
NSCalendar *calendar = [NSCalendar currentCalendar];

//年月日
NSDateComponents *comps = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit |NSWeekdayOrdinalCalendarUnit | NSHourCalendarUnit) fromDate:tomorrowDate];
//weekdayを取得
NSInteger weekday = [comps weekday];

//日時をNSStringからNSDateに変換
NSDate *serverDate = [dateFomatter dateFromString:serverTimeStr];
NSDate *createDate = [dateFomatter dateFromString:createTimeStr];

//二つDate時間の間隔
NSTimeInterval betweenTime = [serverDate timeIntervalSinceDate:createDate];

//年月日分秒
NSDateFormatter *dateFomatter = [[NSDateFormatter alloc]init];
[dateFomatter setDateFormat:@”yyyy-MM-dd HH:mm:ss”];

//stringをformatterに変換
NSDate *stringDate = [dateFomatter dateFromString:string];
[dateFomatter setDateFormat:@”MM-dd”];

//文字列の月日を抽出
NSString *str1 = [dateFomatter stringFromDate:stringDate];

ios7にcontentsizeで高さを取得する方法

参考コード:
[cell.methodTextView.text boundingRectWithSize:CGSizeMake(cell.methodTextView.frame.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:cell.methodTextView.font,NSFontAttributeName, nil] context:nil].size.height

説明:
textviewのtext文字列を呼び出してboundingRectWithSize方法を利用してCGpointを取得する
CGpointでsize.heightを取得

「ios開発」CCArrayの使い方を纏める

1.配列に要素を追加
CCSprite* pRet=CCSprite::create(“test.png”);
pArray->addObject(pRet);

2.要素を削除
pArray->removeObject(pRet);
pArray->removeObjectAtIndex(0);

3. foreachの使い方
CCObject* pObj;
//フォワード
CCARRAY_FOREACH(s_pBulletArray,pObj)
{
CMapNode* pNode=(CMapNode*)pObj;
}
//逆方向
CCARRAY_FOREACH_REVERSE(s_pBulletArray,pObj)
{
CMapNode* pNode=(CMapNode*)pObj;
}

4.forループ遍歴
for (unsigned int i = 0; i <s_pBulletArray->count(); ++i)
{
CCNode* pObj=(CCNode*)s_pBulletArray->objectAtIndex(i);
}

for (int i = arr->count()-1; i>=0 ; –i)

{
CMonster* pObj=(CMonster*)arr->objectAtIndex(i);
bool isCollide = false;
isCollide =rect.intersectsRect(pObj->getCollideRect());
if (isCollide)
{
arr->removeObject(pObj);
}
}

「Objective-C」ios開発でマルチスレッドを作成する方法のまとめ

方法1
NSThread * thread=[[NSThread alloc] initWithTarget:self selector:@selector(_update) object:nil];

方法2
[NSThread detachNewThreadSelector:@selector(_update) toTarget:self withObject:nil];

方法3
[self performSelectorInBackground:@selector(_update) withObject:nil];

方法4
NSOperationQueue *queue=[[NSOperationQueue alloc] init];
[queue addOperationWithBlock:^{
for(int i=0;i<50;i++){
printf(“child thread\n”);
}
}];

方法5
NSOperationQueue * queue=[[NSOperationQueue alloc] init];
[queue setMaxConcurrentOperationCount:2];

NSInvocationOperation * thread1=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_update1) object:nil];
NSInvocationOperation *thread2=[[NSInvocationOperation alloc] initWithTarget:self selector:@selector(_update2) object:nil];

[thread1 setQueuePriority:NSOperationQueuePriorityVeryLow];
[thread2 setQueuePriority:NSOperationQueuePriorityVeryHigh];

[queue addOperation:thread1];
[queue addOperation:thread2];

「ios開発」IOS7でステータスバーのフォントの色を設定する対策

対策
1.plistファイルに下記を追加
View controller-based status bar appearance
値をnoに設定する

2.appDelegateに処理コードを追加
if (IOS7) {
[application setStatusBarStyle:UIStatusBarStyleLightContent];
[application setStatusBarStyle:UIStatusBarStyleDefault];
// [application setStatusBarHidden:YES];

}