iOS系统为UISwitch指定的大小是{51, 31},直接设置UISwitch的宽高是无效的。
代码如下:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UISwitch *aSwitch = [[UISwitch alloc] init];
[self.view addSubview:aSwitch];
UISwitch *bSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 0, 120, 60)];
[self.view addSubview:bSwitch];
NSLog(@"aSwitch.frame: %@", NSStringFromCGRect(aSwitch.frame));
NSLog(@"bSwitch.frame: %@", NSStringFromCGRect(bSwitch.frame));
}
// Xcode控制台日志:
// 2022-03-21 11:00:25.864138+0800 Demo[18880:1309766] aSwitch.frame: {{0, 0}, {51, 31}}
// 2022-03-21 11:00:25.864261+0800 Demo[18880:1309766] bSwitch.frame: {{0, 0}, {51, 31}}
网友评论