posted by 프띠버리 2013. 10. 4. 17:15

guguquizAppDelegate.h


#import <UIKit/UIKit.h>


@interface guguquizAppDelegate : UIResponder <UIApplicationDelegate>


@property (strong, nonatomic) IBOutlet UIWindow *window;

@property (strong, nonatomic) IBOutlet UITabBarController *tabController;


@end




guguquizAppDelegate.m


#import "guguquizAppDelegate.h"


@implementation guguquizAppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

//    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

//    // Override point for customization after application launch.

//    self.window.backgroundColor = [UIColor whiteColor];

    

    self.window.rootViewController = self.tabController;

    [self.window makeKeyAndVisible];

    return YES;

}




GugudnaListViewController.h


#import <UIKit/UIKit.h>


@interface GugudnaListViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>


@end




GugudnaListViewController.m


#import "GugudnaListViewController.h"


@interface GugudnaListViewController ()


@end


@implementation GugudnaListViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


#pragma  - UITableView handler

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return 9;

}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

{

    return 9; // 단수 출력

}


-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

{

    return [NSString stringWithFormat:@"%d ", section + 1];

}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

    NSString *identify = @"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identify];

    if(cell == nil)

    {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identify];

    }

    

    cell.textLabel.text = [NSString stringWithFormat:@"%d x %d", (indexPath.section + 1), (indexPath.row + 1)];

    cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", (indexPath.section + 1) * (indexPath.row + 1)];

    

    return cell;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    self.title = @"구구단 리스트";

    // Do any additional setup after loading the view from its nib.

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end




StartQuizViewController.h


#import <UIKit/UIKit.h>


@interface StartQuizViewController : UIViewController


- (IBAction)onStart:(id)sender;


@end




StartQuizViewController.m


#import "StartQuizViewController.h"

#import "QuizViewController.h"


@interface StartQuizViewController ()


@end


@implementation StartQuizViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    self.title = @"구구단 퀴즈";

    // Do any additional setup after loading the view from its nib.

}


- (IBAction)onStart:(id)sender

{

    QuizViewController *viewController = [[QuizViewController alloc] initWithNibName:@"QuizViewController" bundle:nil];

    [self.navigationController pushViewController:viewController animated:YES];

    viewController.totalQuiz = 10;

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end




QuizViewController.h


#import <UIKit/UIKit.h>


@class StartQuizViewController;

@interface QuizViewController : UIViewController

{

    UILabel *labelFirst;

    UILabel *labelSecond;

    UITextField *testAnswer;

    NSInteger numAnswer;

    StartQuizViewController *mainViewController;

}


@property NSInteger totalQuiz;

@property NSInteger correctAnswer;

@property NSInteger wrongAnswer;

@property (nonatomic, retain) IBOutlet UITextField *textAnswer;

@property (nonatomic, retain) IBOutlet UILabel *labelFirst;

@property (nonatomic, retain) IBOutlet UILabel *labelSecond;

@property (nonatomic, retain) IBOutlet UILabel *labelMark;


- (void)onCheckAnswerAndNext;

- (void)putTheQuiz;


@end




QuizViewController.m


#import "QuizViewController.h"

#import "ResultViewController.h"


@interface QuizViewController ()


@end


@implementation QuizViewController


@synthesize totalQuiz;

@synthesize correctAnswer;

@synthesize wrongAnswer;

@synthesize textAnswer;

@synthesize labelFirst;

@synthesize labelSecond;

@synthesize labelMark;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)putTheQuiz

{

    int gugu_1 = arc4random() % 8 + 1;

    int gugu_2 = arc4random() % 8 + 1;

    

    labelFirst.text = [NSString stringWithFormat:@"%d", gugu_1];

    labelSecond.text = [NSString stringWithFormat:@"%d", gugu_2];

    

    numAnswer = gugu_1 * gugu_2;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

    

    [self putTheQuiz];

    [self.textAnswer becomeFirstResponder];

    

    // next button

    UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"다음" style:UIBarButtonItemStyleDone target:self action:@selector(onCheckAnswerAndNext)];

    self.navigationItem.rightBarButtonItem = nextButton;


    self.title = [NSString stringWithFormat:@"문제 %d", self.correctAnswer + self.wrongAnswer + 1];

}


- (void)viewDidAppear:(BOOL)animated

{

    NSMutableArray *views = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];

    

    if([views count] > 1 && [[views objectAtIndex:[views count] -2] isKindOfClass:[QuizViewController class]])

    {

        // 이전 QuizViewController 제거한다.

        [views removeObjectAtIndex:[views count] - 2];

        self.navigationController.viewControllers = views;

    }

}



- (void)onCheckAnswerAndNext

{

    if([textAnswer.text intValue] == numAnswer)

    {

        self.correctAnswer++;

        self.labelMark.text = @"O";

        

    }

    else

    {

        self.wrongAnswer++;

        [labelMark setTextColor:[UIColor redColor]];

        self.labelMark.text = @"X";

    }

    

    // animation

    self.labelMark.hidden = NO;

    self.labelMark.alpha = 0.0f;

    [UIView animateWithDuration:0.5f animations:^{self.labelMark.alpha = 1.0f;} completion:^(BOOL finished)

     {

         //화면전환

         if(self.totalQuiz == self.correctAnswer + self.wrongAnswer)

         {

             ResultViewController *viewController = [[ResultViewController alloc] initWithNibName:@"ResultViewController" bundle:nil];

             viewController.totalQuiz = self.totalQuiz;

             viewController.correctAnswer = self.correctAnswer;

             [self.navigationController pushViewController:viewController animated:YES];

         }

         else

         {

             QuizViewController *viewController = [[QuizViewController alloc] initWithNibName:@"QuizViewController" bundle:nil];

             viewController.totalQuiz = self.totalQuiz;

             viewController.correctAnswer = self.correctAnswer;

             viewController.wrongAnswer = self.wrongAnswer;

             [self.navigationController pushViewController:viewController animated:YES];

         }

         self.title = @"구구단 퀴즈";

     }];

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end




ResultViewController.h


#import <UIKit/UIKit.h>


@interface ResultViewController : UIViewController


@property NSInteger totalQuiz;

@property NSInteger correctAnswer;


@property (retain, nonatomic) IBOutlet UILabel *labelTotalQuiz;

@property (retain, nonatomic) IBOutlet UILabel *labelCorrectAnswer;

@property (retain, nonatomic) IBOutlet UILabel *labelMessage;


@end




ResultViewController.m


#import "ResultViewController.h"

#import "QuizViewController.h"


@interface ResultViewController ()


@end


@implementation ResultViewController

@synthesize totalQuiz;

@synthesize correctAnswer;

@synthesize labelTotalQuiz;

@synthesize labelCorrectAnswer;

@synthesize labelMessage;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}


- (void)viewDidLoad

{

    [super viewDidLoad];

    // Do any additional setup after loading the view from its nib.

    

    self.labelTotalQuiz.text = [NSString stringWithFormat:@"%d", self.totalQuiz];

    self.labelCorrectAnswer.text = [NSString stringWithFormat:@"%d", self.correctAnswer];

    NSString *message = @"";

    float score = (float)correctAnswer / (float)totalQuiz * 100.0f;

    

    if(score == 100.0)

    {

        message = @" 잘했어요. ";

    }

    else if(score > 80.0f)

    {

        message = @"잘했어요. ";

    }

    else if(score > 60.0f)

    {

        message = @"노력 하셔야 겠네요. ";

    }

    else if(score > 40.0f)

    {

        message = @"부모님이 걱정하십니다. ";

    }

    else if(score > 20.0f)

    {

        message = @"아직 희망이 있어요. ";

    }

    else

    {

        message = @"이를 어쩌나... ";

    }

    self.labelMessage.text = message;

}


- (void)viewDidAppear:(BOOL)animated

{

    NSMutableArray *views = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];

    if([views count] > 1 && [[views objectAtIndex:[views count] - 2] isKindOfClass:[QuizViewController class]])

    {

        // 이전 QuizViewController 제거한다.

        [views removeObjectAtIndex:[views count] - 2];

        self.navigationController.viewControllers = views;

    }

}


- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end


posted by 프띠버리 2013. 10. 4. 17:04

draw.h


#import <UIKit/UIKit.h>


@interface draw : UIView

@property(nonatomic, strong) IBOutlet UISegmentedControl *seg;

@property(nonatomic) CGLineJoin lineJoinStyle;


- (void)setLineDash:(const CGFloat *)pattern count:(NSInteger)count phase:(CGFloat)phase;




@end




draw.m


#import "draw.h"


@implementation draw

@synthesize seg;


- (id)initWithFrame:(CGRect)frame

{

    self = [super initWithFrame:frame];

    if (self) {

        // Initialization code

    }

    return self;

}


- (void)drawRect:(CGRect)rect

{

    

//    // Drawing code

//    if(seg.selectedSegmentIndex == 0)

//    {

//        [self line];

//        NSLog(@" 선택");

//    }


    [self rectangle];

}


- (void)line

{

    // 빨강 직선

    UIBezierPath *path;

    path = [UIBezierPath bezierPath];

    [path setLineWidth:6.0];

    [path moveToPoint:CGPointMake(20, 50)];

    [path setLineCapStyle:kCGLineCapButt];

    [path addLineToPoint:CGPointMake(280, 50)];

    [[UIColor redColor] setStroke];

    [path stroke];


    // 녹색 직전

    UIBezierPath *path2;

    path2 = [UIBezierPath bezierPath];

    [path2 setLineWidth:6.0];

    [path2 moveToPoint:CGPointMake(20, 80)];

    [path2 setLineCapStyle:kCGLineCapSquare];

    [path2 addLineToPoint:CGPointMake(280, 80)];

    [[UIColor greenColor] setStroke];

    [path2 stroke];

    

    // 파란 점선

    UIBezierPath *path3;

    path3 = [UIBezierPath bezierPath];

    CGFloat pattern[]={10, 20, 30, 0};

    [path3 setLineDash:pattern count:4 phase:0];

    [path3 setLineWidth:6.0];

    [path3 moveToPoint:CGPointMake(20, 110)];

    [path3 setLineCapStyle:kCGLineCapButt];

    [path3 addLineToPoint:CGPointMake(280, 110)];

    [[UIColor blueColor] setStroke];

    [path3 stroke];

    

    // 모서리 둥근 직선

    UIBezierPath *path4;

    path4 = [UIBezierPath bezierPath];

    [path4 setLineWidth:20.0];

    [path4 moveToPoint:CGPointMake(20, 140)];

    [path4 setLineCapStyle:kCGLineCapRound];

    [path4 addLineToPoint:CGPointMake(280, 140)];

    [[UIColor whiteColor] setStroke];

    [path4 stroke];

    

    // 꺽인 직선

    UIBezierPath *path5;

    path5 = [UIBezierPath bezierPath];

    [path5 setLineWidth:20.0];

    [path5 moveToPoint:CGPointMake(20, 290)];

    [path5 setLineCapStyle:kCGLineCapButt];

    [path5 addLineToPoint:CGPointMake(150, 180)];

    [path5 addLineToPoint:CGPointMake(280, 290)];

    [[UIColor whiteColor] setStroke];

    [path5 stroke];

    

    // 꺽인 둥근 모서리 직선

    UIBezierPath *path6;

    path6 = [UIBezierPath bezierPath];

    [path6 setLineWidth:20.0];

    [path6 moveToPoint:CGPointMake(20, 360)];

    [path6 setLineCapStyle:kCGLineCapRound];

    [path6 addLineToPoint:CGPointMake(150, 250)];

    [path6 addLineToPoint:CGPointMake(280, 360)];

    [[UIColor whiteColor] setStroke];

    [path6 stroke];

    

    // 꺽인 직선

    UIBezierPath *path7;

    path7 = [UIBezierPath bezierPath];

    [path7 setLineWidth:20.0];

    [path7 moveToPoint:CGPointMake(20, 430)];

    [path7 setLineCapStyle:kCGLineCapSquare];

    [path7 addLineToPoint:CGPointMake(150, 320)];

    [path7 addLineToPoint:CGPointMake(280, 430)];

    [[UIColor whiteColor] setStroke];

    [path7 stroke];


}


- (void)rectangle

{

    UIBezierPath *path1;

    path1 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(50, 320, 220, 90) cornerRadius:20];

    [[UIColor magentaColor] setStroke];

    [[UIColor orangeColor] setFill];

    [path1 fill];

    [path1 stroke];

    

    UIBezierPath *path2;

    path2 = [UIBezierPath bezierPathWithRect:CGRectMake(10, 50, 300, 400)];

    [[UIColor whiteColor] setStroke];

    [path2 setLineWidth:5.0];

    [path2 stroke];

    

    UIBezierPath *path3;

    path3 = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(30, 70, 260, 360) cornerRadius:5];

    [[UIColor whiteColor] setStroke];

    [path3 setLineWidth:5.0];

    [path3 stroke];


}


- (void)setLineDash:(const CGFloat *)pattern count:(NSInteger)count phase:(CGFloat)phase

{


}


@end


posted by 프띠버리 2013. 10. 1. 15:59



헤더화일 혹은 m파일 상단에 선언


// 타이머 변수 선언

NSTimer *timer;

// 시간흐름용 정수

int time;



m 파일에서 코딩하기


// 호출용 메소드 만들기

- (void)timePlus

{

    // 시간흐름용 변수에 메소드가 호출될때마다 1 증가

    time++;

    // 시간을 찍어줄 레이블 생성

    UILabel *timeLabel2 = [[UILabel alloc]init];

    timeLabel2.frame = CGRectMake(255105020);

    // 시간을 레이블에 표시할때 분과  형식으로 보여줌

    timeLabel2.text = [NSString stringWithFormat:@"%02d:%02d", (time/60)%60time%60];

    timeLabel2.font = [UIFont systemFontOfSize:15.0];

    // 시간을 화면에 표시

    [self.view addSubview:timeLabel2];

}



// 처음 화면 보여줄때(viewdidload부분에 추가해야 할 부분)


    // 타이머 변수에 timePlus메소드를 호출하여 1초간격으로 반복하게 

    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timePlus) userInfo:nil repeats:YES];

    // 시간흐름용 변수의 초기값은 0

    time = 0;



우측 상단에 00:00으로 시작하는 시간표시 소스입니다.

시간흐르는 앱 만들때 참고하시라고 올립니다.

timeLabel2.text = [NSString stringWithFormat:@"%02d:%02d", (time/60)%60time%60];

부분이 시간표시하는 부분이니 만드는 방식에 따라 시간, 분, 초 등으로 코딩 가능합니다.