본문 바로가기

프로그래밍

(65)
9. 램덤값 가져오기 arc4random() - 예제 #define RANDOM_INT(MIN, MAX) ((MIN) + arc4random() % ((MAX+1) - (MIN))) - 사용 int rand1 = RANDOM_INT(0,320); int rand2 = RANDOM_INT(0,480);
8. 애니메이션 사용하기 [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:1.0]; // 애니메이션 동작 시간 : 1.0초 [UIView setAnimationDelegate:self]; // 여기서 구현 [UIView setAnimationCurve:UIViewAnimationCurveEaseOut]; // 서서히 느려짐 // 예제... 이 안에서 객체의 위치,크기,알파 등의 변화가 있으면 저절로 애니메이션이 적용된다. //......................................................................... CGAffineTransform transform = CGAffineTransformMakeSc..
7. 타이머 사용 (NSTimer) 헤더파일. @interface MainViewController : UIViewController { NSTimer *timer; UILabel *lblTimeDigit; } @property(retain, nonatomic) NSTimer *timer; @property(retain, nonatomic) UILabel *lblTimeDigit; @end .m 파일. @implementation MainViewController @synthesize timer; @synthesize lblTimeDigit; // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. - (void)viewDidLo..
6. NSMutableArray 사용 및 이미지 동적 생성하기 1. NSMutableArray를 헤더파일에 등록시킨다. @interface MainViewController { NSMutableArray *arrayImages; } @property(retain, nonatomic) NSMutableArray *arrayImages; @end 2. 헤더파일에 등록된 array를 .m 파일에 사용한다. @implementation MainViewController @synthesize arrayImages; // 등록 // 프로그램 시작점 - (void)viewDidLoad { [super viewDidLoad]; [self.view setBackgroundColor:[UIColor blackColor]]; // 배경 셋팅하기 arrayImages = [[NSMuta..
5. 아이콘 만들어 적용하기 1. 아이콘 파일을 준비한다. 아이콘 이미지 크기 - 일반 : 57 x 57 픽셀 - 아이폰 4 : 114 x 114 픽셀 - 아이패드 : 72 x 72 픽셀 아이콘 이미지 종류 : .png ? 글로시 효과와 라운딩 처리는 iOS에서 해주므로 하지 않아도 된다. 2. Xcode로 드래그하여 Resource 그룹에 추가한다. 3. HelloWorld-Info.plist 파일을 클릭하여 나타나는 정보의 목록에서 Icon file 속성을 선택한다. - Icon file : 한가지 모듈 지원 - Icon files : 여러가지 모두 지원 Icon이름을 확장자를 포함하여 직접 써 넣는다.
4. 가속도 센서 지원하기 (UIAccelerometerDelegate) - 가속도 센서를 이용하여 기기를 기울이면 반응하도록 해보자. 1. HelloWorldViewcontroller.h 에 프로토콜을 추가한다. ? Help>Developer Documentation 에서 검색하면 메소드의 원형을 찾을 수 있다. 복사하여 코드에 붙여넣자. HelloWorldViewcontroller.h #import @interface HelloWorldViewController : UIViewController { IBOutlet UILabel *label_hello; IBOutlet UIButton *button_iphone; IBOutlet UIButton *button_ipad; IBOutlet UIButton *button_ipodtouch; IBOutlet UIImageView ..
3. 슬라이더 추가하기 (UISlider) 1. 코드 등록 - Outlet 과 Action 을 추가한다. HelloWorldViewController.h #import @interface HelloWorldViewController : UIViewController { IBOutlet UILabel *label_hello; IBOutlet UIButton *button_iphone; IBOutlet UIButton *button_ipad; IBOutlet UIButton *button_ipodtouch; IBOutlet UIImageView *image_bird; IBOutlet UISlider *slider_alpha; // 슬라이더 아웃렛 등록 } - (IBAction) button1Touched; - (IBAction) button2Touc..
2. 이미지 추가 및 터치 이벤트로 이동시키기 (UIImageView) 1. 이미지 프로젝트에 추가 Resources>Add>Existing Files... 2. xib 파일에 Image View 추가 Image - 보여질 사진으로 셋팅 Drawing>Opaque - png 투명도 셋팅 (체크시 불투명) 3. 코드 추가 HelloWorldViewController.h #import @interface HelloWorldViewController : UIViewController { IBOutlet UILabel *label_hello; IBOutlet UIButton *button_iphone; IBOutlet UIButton *button_ipad; IBOutlet UIButton *button_ipodtouch; IBOutlet UIImageView *image_bird..