吉吉于

iOS学习笔记(1):基本控件

好久没写博客了,假期就鼓捣Macbook了,学学Object-C,这玩意这么火,让人有征服的冲动。

内容:熟悉一下基本控件,实现方法。

参照教程:http://www.tudou.com/listplay/ICHpDsjAHMk/m4nkwDQwLAg.html

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController
@property (weak, nonatomic) IBOutlet UILabel *_lblinfo;
- (IBAction)pressButton:(id)sender;
- (IBAction)playOrStop:(UISwitch *)sender;
- (IBAction)pressState:(UISegmentedControl *)sender;
@property (weak, nonatomic) IBOutlet UIImageView *_imageView;
@end

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
@synthesize _imageView;
@synthesize _lblinfo;

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    _lblinfo.text=@"Nothing";
    _lblinfo.textColor=[UIColor redColor];
    UIImage *img1=[UIImage imageNamed:@"dog.jpg"];
    UIImage *img2=[UIImage imageNamed:@"sheji.gif"];
    _imageView.animationImages=[NSArray arrayWithObjects:img1,img2,nil];
    _imageView.animationDuration=0.5;
    [_imageView startAnimating];
}

- (void)viewDidUnload
{
    [self set_lblinfo:nil];
    [self set_imageView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}
//Round Rect Button
- (IBAction)pressButton:(id)sender {
//    _lblinfo.text=@"你按下了左键";
   NSString *title=[sender titleForState:UIControlStateNormal];
//    if([title isEqualToString:@"左"])
//       {
//           _lblinfo.text=@"你按下了左键";
//       }
//    else
//       {
//           _lblinfo.text=@"你按下了右键";
//       }
//    NSString *s=[[NSString alloc]initWithFormat:@"你按下了%@键",title];
//    _lblinfo.text=s;
      NSString *s=[NSString stringWithFormat:@"你按下了%@键",title];
    _lblinfo.text=s;

}
//Switch
- (IBAction)playOrStop:(UISwitch *)sender {
    if(sender.on){
        [_imageView startAnimating];
    }else{
        [_imageView stopAnimating];
    }
}
//Segmented Control
- (IBAction)pressState:(UISegmentedControl *)sender {
    switch (sender.selectedSegmentIndex) {
        case 0:
            _imageView.animationDuration=0.1f; 
            break;
        case 2:
            _imageView.animationDuration=1.0f;
            break;
        default:
            _imageView.animationDuration=0.5f;
            break;
    }
    [_imageView startAnimating];
}

@end

 下载源码

转载请注明:于哲的博客 » iOS学习笔记(1):基本控件