控件-TextField、Slider、
建一个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/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。