ios 延迟调用 && UIImageView && UILabel && UISegmentedControl && UISwitch && UISlider
//
// 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的更多相关文章
- swift系统学习控件篇:UIbutton+UIlabel+UITextField+UISwitch+UISlider
工作之余,学习下swift大法.把自己的学习过程分享一下.当中的布局很乱,就表在意这些细节了.直接上代码: UIButton+UILabel // // ViewController.swift // ...
- xcode UIImageView创建、图片加载、 音频文件播放、 延迟调用
代码创建 /** 创建UIImageView */ UIImageView * imageView=[[UIImageView alloc]init]; /** 设置尺寸位置 */ imageView ...
- ios开发之--使用UILabel Category 计算UILabel内容大小
在此仅做记录,代码如下:
- UISegmentedControl字体大小,颜色,选中颜色,左边椭圆,右边直线的Button 解决之iOS开发之分段控制器UISegmentedControl
NSArray *segmentedArray = [NSArrayarrayWithObjects:STR(@"Mynews"),STR(@"Systemmes ...
- 【Unity3D】Invoke,InvokeRepeating ,Coroutine 延迟调用,周期性调用
Invoke和InvokeRepeating方法,可以实现延迟调用,和周期调用 第一个是执行一次,第二个是重复执行 void Invoke(string methodName, float time) ...
- 用NodeJs实现延迟调用,规避定时任务的闭包问题
很多人在用NodeJs的setTimeout(callback, delay[, arg][, ...])编写定时任务时,习惯上直接操作callback外部的对象object(闭包的特点).这样做有一 ...
- Unity3d 与IOS 相互调用
Unity3d 与IOS 相互调用 @灰太龙 群63438968 我用的Unity3d 4.2版本,这一节说一下IOS与U3D的交互! 首先在U3D中写个方法:这个时候导出为ios代码必须是真机,模拟 ...
- IOS 多个UIImageView 加载高清大图时内存管理
IOS 多个UIImageView 加载高清大图时内存管理 时间:2014-08-27 10:47 浏览:59人 当我们在某一个View多个UIImageView,且UIImageView都显示的是 ...
- 延迟调用或多次调用第三方的Web API服务
当我们调用第三方的Web API服务的时候,不一定每次都是成功的.这时候,我们可能会再多尝试几次,也有可能延迟一段时间再去尝试调用服务. Task的静态方法Delay允许我们延迟执行某个Task,此方 ...
随机推荐
- 【网络优化】Batch Normalization(inception V2) 论文解析(转)
前言 懒癌翻了,这篇不想写overview了,公式也比较多,今天有(zhao)点(jie)累(kou),不想一点点写latex啦,读论文的时候感觉文章不错,虽然看似很多数学公式,其实都是比较基础的公式 ...
- Faster-rcnn 配置方法
Faster-rcnn 在Linux下的配置方法 感谢@邓学长 建立过程: (下载库的时候要按照库readme 进行操作) opencv 的包下载安装,安装教程 用git命令将这个库下载到本地 fas ...
- ThinkPHP开发笔记-用户登录注册
1.修改模块配置,Application/当前模块名/Conf/config.php <?php return array( //数据库配置信息 'DB_TYPE' => 'mysql', ...
- 【Linux】结合Python 简易实现监控公司网站,邮件发送异常
背景 由于一些原因,博主负责测试的网站的服务器切换到了香港,切换后出现了多次访问超时的情况 于是主动请缨写一个自动监测的脚本,本来准备完全使用shell来写,后来发现shell发送邮件只能在测试机之间 ...
- CSS布局框架 960GS
1.960GS 特点 小巧简单,功能单一(仅仅做排版的工作,其他东西靠自己.)(三个文件:reset.css,960.css,font.css) 界面宽960px,适合目前主流1/2以上显示器都满屏宽 ...
- uva11183最小树形图
本来看数据用临界矩阵可能会超时,还是写了临界矩阵,结果1A了 模板的不能再模板 了 #include<map> #include<set> #include<cmath& ...
- 解决无法启动mysql服务错误1069
之前在服务器上修改了my.ini文件 mysql就一直无法启动 后来把my.ini改回原来的,还是无法启动并报1069错误 在网上查了一下,基本上都是说修改mysql密码,再重新启动,试了一下没作用, ...
- .pth 文件扩展python环境路径
有时候我们不希望把一个库放到 site-packages 下面,而是更愿意把它保留在原始的工程目录中,方便管理和维护. 通常的做法是在程序启动的时候,往sys.path里面增加这个目录,但是这样做非常 ...
- Linux命令 ls -l 输出内容含义详解
Linux命令 ls -l s输出内容含义详解 1. ls 只显示文件名或者文件目录 2. ls -l(这个参数是字母L的小写,不是数字1) 用来查看详细的文件资料 在某个目录下键入ls -l可 ...
- CentOS上部署Django+Nginx+Uwsgi环境
在CentOS上部署Django+Nginx+Uwsgi环境 奇谭 2016-09-01 评论 Linux python django nginx uwsgi VirtualEnv的作用:创建隔 ...