建一个Single View Application的project。
部分代码:
#import <UIKit/UIKit.h>
@interface BIDViewController : UIViewController
@property (strong, nonatomic) IBOutlet UITextField *nameField;
@property (strong, nonatomic) IBOutlet UITextField *numberField;
- (IBAction)textFieldDoneEditing:(id)sender;//为了Done时退出键盘
- (IBAction)backgroundTap:(id)sender;//for 点背景退出键盘
- (IBAction)sliderChanged:(id)sender;
@end
- (IBAction)textFieldDoneEditing:(id)sender {
[sender resignFirstResponder];//取消第一响应者的状态
}//Did End On Exit
- (IBAction)backgroundTap:(id)sender {
[nameField resignFirstResponder];
[numberField resignFirstResponder];
}//Touch down
- (IBAction)sliderChanged:(id)sender {
UISlider *slider = (UISlider *)sender;
int progressAsInt = (int)roundf(slider.value);
sliderLabel.text = [NSString stringWithFormat:@"%d", progressAsInt];
}//slider改变label的值
注意将View的Class改为UIControl,
本文转自老Zhan博客园博客,原文链接:http://www.cnblogs.com/mybkn/archive/2012/03/08/2385213.html,如需转载请自行联系原作者