Posts tagged Objective-C
[iPhone 開発メモ] UIScrollView でスクロールさせる
10大きな画像を表示してそれを自由にスクロールさせる方法
今回はあらかじめ imgname.jpg という画像ファイルを Resource に入れておいてそれを表示させてスクロールさせています。
ViewBased のアプリを新規で作成、名前を「Scroll」とする。
ScrollViewController.h
@interface ScrollViewController : UIViewController{ IBOutlet UIScrollView *scrollView; UIImageView *myImage; } @property (nonatomic, retain) UIScrollView *scrollView; @property (nonatomic, retain) UIImageView *myImage; @end
[iPhone 開発メモ] アプリ内で UIWebView を使って Web ページを表示する
7iPhoen アプリ内で Web ページを表示する方法です。UIWebView を使います。
UIWebViewを表示するためのシンプルなUIViewController – ちびり文
こちらのエントリを参考に IB を使ってやってみました。
(続きを読む…)
[iPhone 開発メモ] アプリから URL を指定して Web ページを Safari で開く
0アプリから URL を指定して Safari で開く方法
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://www.syuhari.jp/blog"]];
[iPhone 開発メモ] 本体の回転を検知する
1iPhone を横方向に回転させた時に検知する方法のメモです。
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)FromInterfaceOrientation {
if(FromInterfaceOrientation == UIInterfaceOrientationPortrait){
// 横向き
} else {
// 縦向き
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
[iPhone 開発メモ] 警告画面の表示
3iPhone アプリで警告画面を表示させる方法です。
警告画面を表示する
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Alert Test"
message:@"Message!!\nThis is Alert Test."
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"One", @"Two", nil];
[alert show];
[alert release];
[iPhone 開発メモ] 画像をドラッグする
5画面に表示された画像を指でドラッグする方法です。
UIImageView クラスを継承した DragView クラスを作成する。
@interface DragView : UIImageView {
CGPoint startLocation;
}
@end
@implementation DragView
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
startLocation = [[touches anyObject] locationInView:self];
[[self superview] bringSubviewToFront:self];
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
CGPoint pt = [[touches anyObject] locationInView:self];
CGRect frame = [self frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[self setFrame:frame];
}
@end;
The iPhone Developer’s Cookbook 購入
0以前から読みたかった「The iPhone Developer’s Cookbook」を購入しました。なぜかアマゾンで購入できなくなったり、予約販売になったりと不思議な本ですが、先日違う本を購入しようとしたときに、購入可能だったので急いで購入しました。今見たらまた予約販売になっていた。
(続きを読む…)
[iPhone] XML を NSXMLParser を使用して解析する
1iPhone では NSXMLDocument がシュミレータでは動作するが実機では動作しないそうなので、NSXMLParser を使用して解析してみました。
解析したのは下記のような XML です。
<?xml version="1.0" encoding="UTF-8"?>
<users>
<user name="hoge" age="20" />
<user name="fuga" age="30" />
</users>
詳解 Objective-C 2.0
1iPhone アプリを作成するべく勉強中なのですが、Objective-C を基本から学ばないとダメだと思い、「詳解 Objective-C 2.0」を購入。
たのしいCocoaプログラミング と違って固い感じの本ですが、かなり深く Objective-C に関して解説されている感じです。ただ、帯には「Mac OSX x iPhone」と書かれていますが、ほとんど iPhone に関しては書かれていないと思います。(まだ全部読んでいないので)
(続きを読む…)
iPhone アプリ開発メモ 時刻を取得する
6※iPhone アプリを開発する勉強中です。自分用に勉強したときのメモです。
非公開API を使用していたためコードを改めました(2010.12.7)
現在時刻を取得する方法
NSTimer で1秒ごとに onTimer メソッドを呼び出し、UILabel clock の内容を更新する。
- (void)onTimer {
NSDate *now = [NSDate date];
[formatter setDateFormat:@"kk"];
int h = [[formatter stringFromDate:now] intValue];
[formatter setDateFormat:@"mm"];
int m = [[formatter stringFromDate:now] intValue];
[formatter setDateFormat:@"ss"];
int s = [[formatter stringFromDate:now] intValue];
clock.text = [NSString stringWithFormat:@"%02d:%02d:%02d", h, m, s];
}
- (void)viewDidLoad {
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(onTimer) userInfo:nil repeats:YES];
}