//

//  ViewController.m

//  UI_Lesson3

//

//  Created by archerzz on 15/8/13.

//  Copyright (c) 2015年 archerzz. All rights reserved.

//

#import "ViewController.h"

@interface ViewController () <UIAlertViewDelegate>

// 活动指示器

@property (nonatomic, strong) UIActivityIndicatorView *indicatorView;

- (void)initUserInterface;

- (void)handleEvent:(id)sender;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

[self initUserInterface];

}

- (void)initUserInterface {

NSLog(@"%@", [NSBundle mainBundle]);

self.view.backgroundColor = [UIColor brownColor];

#pragma mark - UIImageView 图片视图

// 1. 创建图片

UIImage *image = [UIImage imageNamed:@"1"];

// 2. 创建图片视图

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

// 3. 设置属性

// 3.1 设置大小

imageView.bounds = CGRectMake(0, 0, 50, 50);

// 3.2 设置中心点

imageView.center = CGPointMake(CGRectGetMidX(self.view.bounds), 60);

// 3.3 设置缩放方式

imageView.contentMode = UIViewContentModeScaleAspectFill;

// 3.4 设置圆角

imageView.layer.cornerRadius = 25;// 宽高的一半成为圆形

// 3.5 裁剪

imageView.clipsToBounds = YES;

// 3.6 imageView默认情况用户交互是关闭的

imageView.userInteractionEnabled = YES;

// 4. 添加到父视图

[self.view addSubview:imageView];

#pragma mark - UILabel 文本自适应

UILabel *label = ({

UILabel *label = [[UILabel alloc] init];

// 1.1 设置文本

label.text = @"啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊";

// 1.2 设置字体

label.font = [UIFont systemFontOfSize:14];

// 1.3 设置位置大小

label.frame = CGRectMake(0, 60, 150, 0);

// 1.4 设置行数

label.numberOfLines = 0; // 无穷

// 1.5 设置换行模式

label.lineBreakMode = NSLineBreakByCharWrapping;

// 1.6 自适应

[label sizeToFit];

label;

});

// 添加到父视图

[self.view addSubview:label];

#pragma mark - UISegmentedControl 分段控件

// 1. 初始化

UISegmentedControl *segControl = [[UISegmentedControl alloc] initWithItems:@[@"红色", @"紫色"]];

// 2.1 设置中心点

segControl.center = CGPointMake(260, 100);

// 2.2 设置主色调

segControl.tintColor = [UIColor redColor];

// 2.3 添加事件 UIControlEventValueChanged

[segControl addTarget:self

action:@selector(handleEvent:)

forControlEvents:UIControlEventValueChanged];

// 3. 添加到父视图

[self.view addSubview:segControl];

#pragma mark - UISwitch 开关

// 1. 初始化

UISwitch *switchControl = [[UISwitch alloc] init];

// 2.1 设置中心点

switchControl.center = CGPointMake(260, 160);

// 2.2 设置主色调

switchControl.tintColor = [UIColor redColor];

// 2.3 设置开启后的色调

switchControl.onTintColor = [UIColor grayColor];

// 2.4 设置按钮颜色

switchControl.thumbTintColor = [UIColor orangeColor];

// 2.5 添加事件

[switchControl addTarget:self

action:@selector(handleEvent:)

forControlEvents:UIControlEventValueChanged];

// 3. 添加到父视图

[self.view addSubview:switchControl];

#pragma mark - UISlider 滑条

// 1. 初始化

UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(0, 300, 375, 30)];

// 2. 设置属性

// 2.1 设置主色调

slider.tintColor = [UIColor greenColor];

// 2.2 左侧颜色

slider.minimumTrackTintColor = [UIColor grayColor];

// 2.3 右侧颜色

slider.maximumTrackTintColor = [UIColor redColor];

// 2.4 按钮颜色

slider.thumbTintColor = [UIColor purpleColor];

// 2.5 添加事件

[slider addTarget:self

action:@selector(handleEvent:)

forControlEvents:UIControlEventValueChanged];

// 3. 添加到父视图

[self.view addSubview:slider];

#pragma mark - UIProgressView 进度条

// 1. 初始化

UIProgressView *progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 350, 375, 30)];

// 2. 设置属性

// 3. 添加到父视图

[self.view addSubview:progressView];

#pragma mark - UIActivityIndicatorView 活动指示器

self.indicatorView = ({

// 1. 初始化

UIActivityIndicatorView *indicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

// 2.1 设置中心点

indicatorView.center = self.view.center;

// 2.2 打开隐藏

indicatorView.hidesWhenStopped = NO;

indicatorView;

});

// 3. 添加到父视图

[self.view addSubview:self.indicatorView];

#pragma mark - 延迟调用

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"警告" message:@"请输入用户名或密码" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

[alertView show];

});

#pragma mark - UIActionSheet

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"分享" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"腾讯微博" otherButtonTitles:@"新浪微博", @"人人网", nil];

[actionSheet showInView:self.view];

#pragma mark - UIAlertController 补充

}

- (void)handleEvent:(id)sender {

// 判断sender是否为UISegmentedControl的对象

if ([sender isKindOfClass:[UISegmentedControl class]]) {

// 强转

UISegmentedControl *segControl = (UISegmentedControl *)sender;

NSLog(@"index = %ld", segControl.selectedSegmentIndex);

if (segControl.selectedSegmentIndex == 1) {

self.view.backgroundColor = [UIColor purpleColor];

} else {

self.view.backgroundColor = [UIColor redColor];

}

} else if ([sender isKindOfClass:[UISwitch class]]) {

UISwitch *switchControl = (UISwitch *)sender;

if (switchControl.isOn) {

[self.indicatorView startAnimating];

} else {

[self.indicatorView stopAnimating];

}

} else if ([sender isKindOfClass:[UISlider class]]) {

UISlider *slider = (UISlider *)sender;

self.view.alpha = 1 - slider.value;

}

}

#pragma mark - UIAlertViewDelegate method

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {

if (buttonIndex == 0) {

NSLog(@"取消");

} else if (buttonIndex == 1) {

NSLog(@"确定");

}

}

@end

ios 延迟调用 && UIImageView && UILabel && UISegmentedControl && UISwitch && UISlider的更多相关文章

  1. swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider

    工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...

  2. xcode UIImageView创建、图片加载、 音频文件播放、 延迟调用

    代码创建 /** 创建UIImageView */ UIImageView * imageView=[[UIImageView alloc]init]; /** 设置尺寸位置 */ imageView ...

  3. ios开发之--使用UILabel Category 计算UILabel内容大小

    在此仅做记录,代码如下:

  4. UISegmentedControl字体大小,颜色,选中颜色,左边椭圆,右边直线的Button 解决之iOS开发之分段控制器UISegmentedControl

        NSArray *segmentedArray = [NSArrayarrayWithObjects:STR(@"Mynews"),STR(@"Systemmes ...

  5. 【Unity3D】Invoke,InvokeRepeating ,Coroutine 延迟调用,周期性调用

    Invoke和InvokeRepeating方法,可以实现延迟调用,和周期调用 第一个是执行一次,第二个是重复执行 void Invoke(string methodName, float time) ...

  6. 用NodeJs实现延迟调用,规避定时任务的闭包问题

    很多人在用NodeJs的setTimeout(callback, delay[, arg][, ...])编写定时任务时,习惯上直接操作callback外部的对象object(闭包的特点).这样做有一 ...

  7. Unity3d 与IOS 相互调用

    Unity3d 与IOS 相互调用 @灰太龙 群63438968 我用的Unity3d 4.2版本,这一节说一下IOS与U3D的交互! 首先在U3D中写个方法:这个时候导出为ios代码必须是真机,模拟 ...

  8. IOS 多个UIImageView 加载高清大图时内存管理

    IOS 多个UIImageView 加载高清大图时内存管理 时间:2014-08-27 10:47  浏览:59人 当我们在某一个View多个UIImageView,且UIImageView都显示的是 ...

  9. 延迟调用或多次调用第三方的Web API服务

    当我们调用第三方的Web API服务的时候,不一定每次都是成功的.这时候,我们可能会再多尝试几次,也有可能延迟一段时间再去尝试调用服务. Task的静态方法Delay允许我们延迟执行某个Task,此方 ...

随机推荐

  1. hadoop项目实战--ETL--(一)项目分析

    项目描述 一 项目简介 在远程服务器上的数据库中有两张表,user 和order,现需要对表中的数据做分析,将分析后的结果再存到mysql中.两张表的结构如下图所示 现需要分析每一天user和,ode ...

  2. webservice获取天气信息

    效果 1.eclipse中新建一个Java项目 2.通过命名获取天气的客户端信息 首先,打开天气网站http://ws.webxml.com.cn/WebServices/WeatherWS.asmx ...

  3. angular $q的学习笔记转帖

    http://blog.segmentfault.com/bornkiller/1190000000402555 angular $q的一个不错的学习笔记

  4. flask学习(六):URL传参

    1. 参数的作用:可以在相同的URL,但是指定不同的参数,来加载不同的数据 例如:简书上每一篇文章前面的URL相同,只是后面的参数不同 2. 在flask中如何使用参数: 注意: 1) 参数需要放在两 ...

  5. ngnix配置自解

    全局配置 user [user] [group]; #只有被设置为用户或用户组的成员才有nginx的启动权限.(#user nobody nobody <=> user nobody no ...

  6. 【Windows】netsh动态配置端口转发

    文章转载自傲风 使用多个虚拟机,将开发环境和工作沟通环境分开(即时通,办公系统都只能在windows下使用-),将开发环境的服务提供给外部访问时,需要在主机上通过代理配置数据转发. VirtualBo ...

  7. java和python互相调用

      java和python互相调用  作者:xuaijun  日期:2017.1.1 python作为一种脚本语言,大量用于测试用例和测试代码的编写,尤其适用于交互式业务场景.实际应用中,很多网管系统 ...

  8. 基于vue-cli,测试非父子传值时,碰到 keep-alive的神奇

    非父子传值测试 一直都很好奇非父子传值到底如何,结果入坑许久才爬出来,才知道在脚手架里测试就是坑. 问题: 测试非父子传值时,由于组件之间是通过路由进行跳转,值传过去又被刷掉 思路: 因为路由跳转,相 ...

  9. 双系统下ubuntu不能访问658GB卷,磁盘挂载失败。

    win10+ubuntu双系统出现以下错误: Error mounting /dev/sda5 at /media/captain/AC8CF85B8CF8218E: Command-line `mo ...

  10. GitHub:Git的使用

    1.下载安装后设置姓名和邮箱地址 $ git config --global user.name "yourGithubName" $ git config --global us ...