UIAppearence协议
- 基类是<NSObject>协议
appearence换肤
- 不是所有的属性都能换肤,需要包含宏
UI_APPEARANCE_SELECTOR
。 - 需要在创建前先设置外观,否则无效
- (IBAction)changeColor:(UISegmentedControl *)sender { switch (sender.selectedSegmentIndex) { case 0: // 蓝色 [UISwitch appearance].onTintColor = [UIColor blueColor]; break; case 1: // 红色 [UISwitch appearance].onTintColor = [UIColor redColor]; break; case 2: // 橙色 [UISwitch appearance].onTintColor = [UIColor orangeColor]; break; } // 重新添加控件 [self.view removeFromSuperview]; [[UIApplication sharedApplication].keyWindow addSubview:self.view]; // 比下面的效果好 // [self.switch_ removeFromSuperview]; // [self.view addSubview:self.switch_]; }