直接修改UISwitch frame是没有效果的。
// This class enforces a size appropriate for the control, and so the frame size is ignored.
那么进行 CGAffineTransformMakeScale
直接对UISwitch缩放,最后显示也会出现问题的.
正确的做法是将UISwitch用view包起来,然后缩放view就可以得到正确的效果。
UISwitch *switchButton = [[UISwitch alloc] init];
[switchButton addTarget:self action:@selector(switchButtonAction:) forControlEvents:UIControlEventValueChanged];
UIView *switchView = [UIView new];
switchView.frame = switchButton.bounds;
switchView.transform = CGAffineTransformMakeScale(0.65, 0.65);
switchView.ef_left = view.ef_width - switchView.ef_width;
switchView.ef_top = (view.ef_height - switchView.ef_height)/2.f;
[switchView addSubview:switchButton];
[view addSubview:switchView];
网友评论