#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
UITextField *text;
}
@property (strong, nonatomic) UIWindow *window;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.backgroundColor=[UIColor whiteColor];
//输入滑动条的大小
UISlider *sld = [[UISlider alloc]initWithFrame:CGRectMake(50, 50, 100, 20)];
//给滑动条增加事件,为了给后面的单行文本框中增加对应的数值
[sld addTarget:self action:@selector(act:) forControlEvents:UIControlEventValueChanged];
//slide的大小
sld.minimumValue=1;
sld.maximumValue=20;
[self.window addSubview:sld];
//单行文本的大小
text = [[UITextField alloc]initWithFrame:CGRectMake(160, 50, 50, 20)];
text.text=@"1";
text.backgroundColor = [UIColor blueColor];
//单行文本是否可输入
text.enabled=NO;
//对齐方式 textalignment
text.textAlignment=NSTextAlignmentCenter;
[self.window addSubview:text];
[self.window makeKeyAndVisible];
return YES;
}
-(void)act:(UISlider *)sender
{
NSLog(@"%f",sender.value);
//把进度条通过send.value方式读出来,转后转化成整形值 再通过NSString stringWithFormat:@"%d"方式放到单行文本框中去
text.text=[NSString stringWithFormat:@"%d",(int)sender.value];
}