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,此方 ...
随机推荐
- rsync | scp文件同步命令使用
现在有一台服务器A,目录/data2/abc下存在若干文件夹和文件,需要复制到服务器B中.这时,可以在服务器A上执行rsync或者scp命令,将文件夹或文件复制到服务器B中. SCP: scp /da ...
- 字典树应用 - poj1002
字典树应用 - poj 1002 Description Businesses like to have memorable telephone numbers. One way to make a ...
- 解题报告:hdu1008 Elvator
2017-09-07 19:30:22 writer:pprp 比较顺利,最近生活出现了各种问题, 发生了很多矛盾,我要耐下心来,最重要的不是努力不努力,而是选择 希望我能处理好人际关系还有学业上的压 ...
- 数据可视化——matplotlib(2)
导入相关模块 import matplotlib.pyplot as plt import numpy as np import pandas as pd 图表设置 添加X.Y轴标签以及图标标题 a ...
- springmvc的@Validated/@Valid注解使用和BindingResult bindingResult
关于@Valid和Validated的比较 @Valid是使用hibernate validation的时候使用 @Validated 是只用spring Validator 校验机制使用 一:@V ...
- cordova安卓sdk
Android SDK在线更新镜像服务器来下载安装: 1.北京化工大学镜像服务器地址: IPv4: ubuntu.buct.edu.cn/ 端口:80 IPv4: ubuntu.buct.cn/ 端口 ...
- ls/vi等 command not found
输入一下命令即可 export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin source / ...
- LightOJ - 1151概率dp+高斯消元
概率dp+高斯消元 https://vjudge.net/problem/LightOJ-1151 题意:刚开始在1,要走到100,每次走的距离1-6,超过100重来,有一些点可能有传送点,可以传送到 ...
- for each/in/of的解释and example
for-of 循环:代码示例for (var value of myArray) {console.log(value);}循环的对象需为一个数组 无法记录索引 可以相应break.continue. ...
- 重新学习MySQL数据库7:详解MyIsam与InnoDB引擎的锁实现
重新学习Mysql数据库7:详解MyIsam与InnoDB引擎的锁实现 说到锁机制之前,先来看看Mysql的存储引擎,毕竟不同的引擎的锁机制也随着不同. 三类常见引擎: MyIsam :不支持事务,不 ...