DataViewController.h头文件中的代码
#import <UIKit/UIKit.h>
@interface DataViewController : UIViewController
@property (strong, nonatomic) UISwitch *mySwitch;
DataViewController.m文件中的代码
#import "DataViewController.h"
@interface DataViewController ()
@end
@implementation DataViewController
@synthesize mySwitch;
-(IBAction)addSwitch
{
self.mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(30,30,0,0)];
[self.mySwitch setOn:true];
[self.view addSubview:self.mySwitch];
}