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,此方 ...
随机推荐
- Build hadoop 2.5.2 with Java8
mvn clean package -Pdist,native -DskipTests -Dtar -Dmaven.javadoc.skip=true
- TensorFlow备忘录——conv2d函数
卷积函数 TensorFlow学习备忘录 tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_forma ...
- Ubuntu下搭建Spark运行环境
安装Spark的方式 现在有两种安装方式: 安裝spark notebook:已經把spark, scala, hadoop等等包起來了,裝好就能用GUI介面操作,適合測試用. 傳統方式安裝:慢慢裝s ...
- 设置table的td宽度,不随文字变宽
页面中table宽度设置width="600px"之后,宽度仍然不是固定的,文字太长后不换行,把table都撑变形了. 解决办法: table 设置 宽度,绝对宽度和相对都可以 t ...
- 格雷码C++实现
格雷码C++实现 题目 给定一个整数n,请返回n位的格雷码,顺序从0开始,要求递归实现. 格雷码: 在一组数的编码中,若任意两个相邻的代码只有一位二进制数不同,则称这种编码为格雷码(Gray Code ...
- SpringIOC源码分析总结
大致的加载过程: spring ioc容器的加载,大体上经过以下几个过程: 资源文件定位.解析.注册.实例化 1.资源文件定位:主要发生在ApplicationContext中,由于applicati ...
- nyoj744——异或(sb题)
蚂蚁的难题(一) 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 小蚂蚁童鞋最近迷上了位运算,他感觉位运算非常神奇.不过他最近遇到了一个难题: 给定一个区间[a,b] ...
- Neutron二层网络服务实现原理
网络 网络(network)是一个隔离的二层网段,类似于物理网络世界中的虚拟 LAN (VLAN).更具体来讲,它是为创建它的租户而保留的一个广播域,或者被显式配置为共享网段.端口和子网始终被分配 ...
- python:打包成exe程序
1.需要安装 py2exe 2.示例代码: #exetest.py #创建一个gui界面,只用一个标签和按钮,无功能 from Tkinter import * win = Tk() label = ...
- JDK的多线程与并发库
1.创建多线程 public class MultiThread { public static void main(String[] args) { // 通过继承Thread类 Thread th ...