1.建立專案,規劃一個Segmented Control及Label兩個UI物件,並建立Outlet連結。
2.輸入程式
以下為DLIViewControl.h的程式列表;
@property (strong, nonatomic) IBOutlet UILabel *result;
@property (strong, nonatomic) IBOutlet UISegmentedControl *segmentControl;
- (IBAction)valueChanged:(id)sender;
@end
以下為DLIViewControl.m的程式列表;
#import "DLIViewController.h"
@interface DLIViewController ()
@end
@implementation DLIViewController
@synthesize result;
@synthesize segmentControl;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)valueChanged:(id)sender {
switch (segmentControl.selectedSegmentIndex) {
case 0:
[result setText: @"First"];
break;
case 1:
[result setText: @"Second"];
default:
break;
}
}
@end
3.執行結果
沒有留言:
張貼留言