[IOS实例小计]计数器--启示就是简单的按钮方法操作,主要学习目
来源:未知 责任编辑:责任编辑 发表时间:2015-09-17 09:43 点击:次
直接上代码:
p>
p>//
p>// CountMeViewController.h
p>// ImageView
p>//
p>// Created by zhang xujun on 13-9-9.
p>// Copyright (c) 2013年 zhang xujun. All rights reserved.
p>//
p>
p>#import <UIKit/UIKit.h>
p>
p>@interface CountMeViewController : UIViewController
p>
p>
p>@property (strong,nonatomic) IBOutlet UIButton *returnSuperView;
p>@property (strong,nonatomic) IBOutlet UILabel *countLabel;
p>@property (strong,nonatomic) IBOutlet UIButton *add;
p>@property (strong,nonatomic) IBOutlet UIButton *sub;
p>@property (strong,nonatomic) IBOutlet UIButton *reset;
p>-(IBAction)returnSuperView:(id)sender;
p>-(IBAction)countAdd:(id)sender;
p>-(IBAction)countSub:(id)sender;
p>-(IBAction)reset:(id)sender;
p>@end
p>//
p>// CountMeViewController.m
p>// ImageView
p>//
p>// Created by zhang xujun on 13-9-9.
p>// Copyright (c) 2013年 zhang xujun. All rights reserved.
p>//
p>
p>#import "CountMeViewController.h"
p>
p>@interface CountMeViewController ()
p>
p>@end
p>
p>@implementation CountMeViewController
p>@synthesize returnSuperView;
p>@synthesize countLabel;
p>@synthesize add;
p>@synthesize sub;
p>@synthesize reset;
p>
p>int count = 0;
p>
p>- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
p>{
p> self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
p> if (self) {
p> // Custom initialization
p> }
p> return self;
p>}
p>
p>- (void)viewDidLoad
p>{
p> [super viewDidLoad];
p> self.countLabel.text = @"0";
p>
p>}
p>-(void)countAdd:(id)sender{
p>
p> if (count>=99) {
p> return;
p> }
p> NSString *addCount = [[NSString alloc] initWithFormat:@"%d",++count];
p> self.countLabel.text = addCount;
p>
p>
p>}
p>-(void)countSub:(id)sender{
p>
p> if (count<=0) {
p> return;
p> }
p> NSString *subCount = [[NSString alloc] initWithFormat:@"%d",--count];
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>