@interface QYViewController ()
@property (nonatomic,strong)UIImageView image;
@property (nonatomic) UISlider slider;
@property (nonatomic) UILabel imageNo;
@property (nonatomic) UISlider slider1;
@property (nonatomic) UISwitch *swith;
@end
@implementation QYViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_slider = [[UISlider alloc] initWithFrame:CGRectMake( 20, 430, 280, 30)];
_slider.minimumValue = 1;
_slider.maximumValue = 9;
[_slider addTarget:self action:@selector(touch:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_slider];
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 30, 60, 30)];
button.backgroundColor = [UIColor greenColor];
[button setTitle:@"设置" forState:UIControlStateNormal];
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:button];
_image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"唯美14.jpg"]];
_image.frame = CGRectMake(0, 0, 320, 480);
[self.view addSubview:_image];
}
-(void)touch:(UISlider *)slider
{
int aa = floor(_slider.value);
NSString *imageName = [NSString stringWithFormat:@"唯美%d.png",aa];
_image.image = [UIImage imageNamed:imageName];
_image.frame = CGRectMake(50, 100, 200, 300);
[self.view addSubview:_image];
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 50, 90, 30)];
label.text = [NSString stringWithFormat:@"%.f/9",_slider.value ];
label.backgroundColor = [UIColor greenColor];
label.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:label];
NSLog(@"%f",_slider.value);
}
-(void)click:(UIButton *)button
{
/*
UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:@ delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"喜欢" otherButtonTitles:@"确认", nil];
[action showInView:self.view];
*/
UIImageView *view1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 400, 320, 80)];
view1.backgroundColor = [UIColor brownColor];
[self.view addSubview:view1];
_slider1 = [[UISlider alloc] initWithFrame:CGRectMake( 70, 440, 230, 30)];
;
[self.view addSubview:_slider1];
pragma mark 设置开关
_swith = [[UISwitch alloc] initWithFrame:CGRectMake(100, 400, 40, 20)];
// _swith.backgroundColor = [UIColor blueColor];
[_swith addTarget:self action:@selector(swif) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:_swith];
pragma mark 设置Label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 400, 50, 30)];
label.text = @"情景模式";
label.textColor = [UIColor blackColor];
label.adjustsFontSizeToFitWidth = YES;
[self.view addSubview:label];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 440, 50, 30)];
label1.text = @"图片缩放";
label1.textColor = [UIColor blackColor];
label1.adjustsFontSizeToFitWidth = YES;
[self.view addSubview:label1];
}
-(void)change
{
//transform是NSAffineTransform的类方法,NSAffineTransform类主要实现图形的缩放,旋转和平移操作。在Xcode10.4之后,NSAffineTransform类已经被分割为基础工具包和应用开发框架。
_image.transform = CGAffineTransformMakeScale(_slider1.value, _slider1.value);
}
-(void)swif
{
if (_swith.on) {
self.view.backgroundColor = [UIColor darkGrayColor];
} else{
self.view.backgroundColor = [UIColor whiteColor];
}
}
@end
近期评论