控件-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,

posted on 2012-03-08 14:21  老Zhan  阅读(313)  评论(0编辑  收藏  举报