第一个iOS应用程序开发

来源:互联网 发布:淘宝商家信用卡费率 编辑:程序博客网 时间:2024/06/05 09:32
////  ViewController.m//  ZhiTouZi////  Created by mac on 15-10-28.//  Copyright (c) 2015年 mac. All rights reserved.//#import "ViewController.h"@interface ViewController ()@end@implementation ViewController{    UILabel *leftDice;    UILabel *rightDice;    UIButton *beginPlay;}- (void)viewDidLoad {    [super viewDidLoad];    [self initViews];    // Do any additional setup after loading the view, typically from a nib.}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}-(void)initViews{         leftDice=[[UILabel alloc]initWithFrame:CGRectMake(60, 100, 60, 100)];    [leftDice setBackgroundColor:[UIColor yellowColor]];    [leftDice setText:@"1"];    [leftDice setTextAlignment:(NSTextAlignmentCenter)];    [leftDice setTextColor:[UIColor blueColor]];    [self.view addSubview:leftDice];            rightDice=[[UILabel alloc]initWithFrame:CGRectMake(250, 100, 60, 100)];    [rightDice setBackgroundColor:[UIColor yellowColor]];    [rightDice setText:@"1"];    [rightDice setTextColor:[UIColor blueColor]];    [rightDice setTextAlignment:(NSTextAlignmentCenter)];    [self.view addSubview:rightDice];        beginPlay=[UIButton buttonWithType:UIButtonTypeRoundedRect];    [beginPlay setFrame:CGRectMake(150, 350, 75, 30)];    [beginPlay setTitle:@"开始掷骰子" forState:UIControlStateNormal];    [beginPlay setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];    [beginPlay addTarget:self action:@selector(clickPlay:) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:beginPlay];}-(void)clickPlay:(UIButton *)sender{        NSInteger left=arc4random()%5+2;    NSInteger right=arc4random()%5+2;        self->leftDice.text=[NSString stringWithFormat:@"%ld",(long)left];    self->rightDice.text=[NSString stringWithFormat:@"%ld",(long)right];                            if (left>=right) {            UIAlertView *alert = [[UIAlertView alloc]                                  initWithTitle:@"" message:@"我赢了!!!" delegate:self cancelButtonTitle:@"哈哈再来一次" otherButtonTitles:@"不跟你玩儿了", nil];            [alert show];        } else {            UIAlertView *alert1 = [[UIAlertView alloc]                                  initWithTitle:@"" message:@"你赢了!!!" delegate:self cancelButtonTitle:@"哈哈再来一次" otherButtonTitles:@"不跟你玩儿了", nil];            [alert1 show];        }            }    @end


0 0
原创粉丝点击