//
// ViewController.m
// UI2_UISwitch与UIActivity
//
// Created by zhangxueming on 15/7/7.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//开关的尺寸固定大小(51*31)
UISwitch *sw = [[UISwitch alloc] initWithFrame:CGRectMake(100, 200, 0, 0)];
NSLog(@"sw = %@", sw);
sw.thumbTintColor = [UIColor redColor];
sw.tintColor = [UIColor blueColor];
sw.onTintColor = [UIColor yellowColor];
[sw addTarget:self action:@selector(swichValueChanged:) forControlEvents:UIControlEventValueChanged];
//动画打开开关
[sw setOn:YES animated:YES];
[self.view addSubview:sw];
//活动指示器
UIActivityIndicatorView * indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[self.view addSubview:indicatorView];
indicatorView.center = self.view.center;
[indicatorView startAnimating];
indicatorView.tag =100;
self.view.backgroundColor = [UIColor blackColor];
}
- (void)swichValueChanged:(UISwitch *)sw
{
NSLog(@"sw value = %i", sw.on);
UIActivityIndicatorView *indicator = (UIActivityIndicatorView *)[self.view viewWithTag:100];
if (sw.isOn) {
[indicator startAnimating];
}
else{
[indicator stopAnimating];
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
转载于:https://www.cnblogs.com/0515offer/p/4638784.html
相关资源:数据结构—成绩单生成器