[Xcode]구구단 2단 출력하기
Xcode에서 프로젝트 만들어서 간단한 프로그램을 만드는 것은 패스
구구단 2단 출력하는 소스스
ViewController.m 화일에 소스를 입력한다.
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// 사용할 라벨 배열 정의
UILabel *lb[9];
for(int i=1; i < 10; i++){
// 라벨 초기화
lb[i] = [[UILabel alloc] init];
// 라벨 위치 설정(라벨 x좌표, 라벨 y좌표, 라벨 폭, 라벨 높이)
lb[i].frame = CGRectMake(10, i * 20, 400, 20);
// 라벨 문자열 설정
lb[i].text = [NSString stringWithFormat:
@" 2 * %d = %d", i, 2 * i];
[self.view addSubview:lb[i]];
self.view.backgroundColor = [UIColor whiteColor];
}
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end