改变大小需要设置transform
@property (nonatomic, strong) UISwitch *matchOpenSwitch;
注意:调试 一下Switch的�x、y,以改变比例transform
_switchBackView = [[UIView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width/375*335-15-35, [UIScreen mainScreen].bounds.size.width/375*(81-20)/2, [UIScreen mainScreen].bounds.size.width/375*35, [UIScreen mainScreen].bounds.size.width/375*20)];
self.switchBackView.backgroundColor = [UIColor redColor];
[self.openBackView addSubview:self.switchBackView];
// 调试 一下matchOpenSwitch的�x、y
_matchOpenSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(-[UIScreen mainScreen].bounds.size.width/375*10, -[UIScreen mainScreen].bounds.size.width/375*35/2/2, [UIScreen mainScreen].bounds.size.width/375*35, [UIScreen mainScreen].bounds.size.width/375*20)];
self.matchOpenSwitch.onTintColor = RGBA(255, 196, 15, 1);
//改变大小的关键代码(不能改变frame的大小,只能等比例缩放)
self.matchOpenSwitch.transform = CGAffineTransformMakeScale(0.7, 0.7);
[self.switchBackView addSubview:self.matchOpenSwitch];
[self.matchOpenSwitch addTarget:self action:@selector(changeOpenSwitchAction:) forControlEvents:UIControlEventValueChanged];
[self.matchOpenSwitch setOn:NO animated:YES];
- (void)changeOpenSwitchAction:(UISwitch *)mySwitch {
/** :默认 未开启 控件switch */
if ([mySwitch isOn]) {
[LCM_AlertViewFactory showToastWithMessage:@"打开"];
} else {
[LCM_AlertViewFactory showToastWithMessage:@"关闭"];
}
}
网友评论