IOS UI 第六篇:基本UI
加两个UI模块
{
[self begin1];
[self begin2];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)begin1{
UIActivityIndicatorView *viView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
viView.center = CGPointMake(160, 300);
viView.color = [UIColor blueColor];
viView.hidesWhenStopped = NO;
[viView startAnimating];
[viView stopAnimating];
[self.view addSubview:viView];
}
-(void)begin2{
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
mySwitch.onTintColor = [UIColor redColor];
mySwitch.on = NO;
[mySwitch setOn:YES animated:YES];
[mySwitch addTarget:self action:@selector(onButton:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mySwitch];
}
-(void)onButton:(id)sender{
NSLog(@":::%@", sender);
UISwitch *sw = sender;
if(sw.on) NSLog(@"ON");
else NSLog(@"OFF");
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
if(textField.text.length >= 6 && !range.length)
return NO;
return YES;
}
NSLog(@"%d-%d-%d",range.length, range.location, textField.text.length);
if (textField == self.nameTextField) {
if(textField.text.length >= 6 && !range.length)
return NO;
return YES;
}
if (textField == self.passwordTextField){
if(textField.text.length >= 4 && !range.length)
return NO;
return YES;
}
return YES;
}
//将输入框取消第一响应者,键盘就睡自动收回
[self.nameTextField resignFirstResponder];
[self.passwordTextField resignFirstResponder];
}
//在销毁的时候将自己在通知中心中移除
[[NSNotificationCenter defaultCenter]removeObserver:self];
}
NSLog(@"textFiled 键盘的return键被点击");
[textField resignFirstResponder];
NSLog(@"开始搜索!!!");
return YES;
}

@property (strong, nonatomic) IBOutlet UIView *subView;
@property (nonatomic, assign)float red;
@property (nonatomic, assign)float blue;
@property (nonatomic, assign)float green;
@property (nonatomic, assign)float alpha;
@property (weak, nonatomic) IBOutlet UILabel *redLabel;
@property (weak, nonatomic) IBOutlet UILabel *greenLabel;
@property (weak, nonatomic) IBOutlet UILabel *blueLabel;
@property (weak, nonatomic) IBOutlet UILabel *alphaLabel;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
_redLabel.text = [NSString stringWithFormat:@"%%50"];
_blueLabel.text = [NSString stringWithFormat:@"%%50"];
_greenLabel.text = [NSString stringWithFormat:@"%%50"];
_alphaLabel.text = [NSString stringWithFormat:@"%%50"];
_red = _green = _blue = _alpha = 0.5;
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
// Do any additional setup after loading the view, typically from a nib.
UISlider *slide = [[UISlider alloc] initWithFrame:CGRectMake(10, 300, 300, 60)];
slide.minimumValue = 0;
slide.maximumValue = 1;
[slide setValue:0.5 animated:YES];
[slide addTarget:self action:@selector(onSliderChange:) forControlEvents:UIControlEventValueChanged];
//[self.view addSubview:slide];
}
-(void)onSliderChange:(id)sender{
NSLog(@"slider:%@", sender);
UISlider *slider = sender;
self.subView.alpha = slider.value;
}
- (IBAction)blueSlider:(id)sender {
UISlider *slider = sender;
_blue = slider.value;
_blueLabel.text = [NSString stringWithFormat:@"%%%.0lf", slider.value*100];
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
}
- (IBAction)greenSlider:(id)sender {
UISlider *slider = sender;
_green = slider.value;
_greenLabel.text = [NSString stringWithFormat:@"%%%.0lf", slider.value*100];
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
}
- (IBAction)redSlider:(id)sender {
UISlider *slider = sender;
_red = slider.value;
_redLabel.text = [NSString stringWithFormat:@"%%%.0lf", slider.value*100];
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
}
- (IBAction)alphaSlider:(id)sender {
UISlider *slider = sender;
_alpha = slider.value;
_alphaLabel.text = [NSString stringWithFormat:@"%%%.0lf", slider.value*100];
self.subView.backgroundColor = [UIColor colorWithRed:_red green:_green blue:_blue alpha:_alpha];
}

{
[self begin1];
[self begin2];
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
-(void)begin1{
UIActivityIndicatorView *viView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
viView.center = CGPointMake(160, 300);
viView.color = [UIColor blueColor];
viView.hidesWhenStopped = NO;
[viView startAnimating];
[viView stopAnimating];
[self.view addSubview:viView];
}
-(void)begin2{
UISwitch *mySwitch = [[UISwitch alloc] initWithFrame:CGRectMake(100, 100, 200, 50)];
mySwitch.onTintColor = [UIColor redColor];
mySwitch.on = NO;
[mySwitch setOn:YES animated:YES];
[mySwitch addTarget:self action:@selector(onButton:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:mySwitch];
}
-(void)onButton:(id)sender{
NSLog(@":::%@", sender);
UISwitch *sw = sender;
if(sw.on) NSLog(@"ON");
else NSLog(@"OFF");
}
UIView *redView;
CGPoint beginPoint;
BOOL canMove;
BOOL mark;
}
- (void)viewDidLoad
{
[super viewDidLoad];
redView=[[UIView alloc]initWithFrame:CGRectMake(-320, 0, 320, 480)];
redView.backgroundColor=[UIColor redColor];
[self.view addSubview:redView];
mark = 0;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark--
#pragma mark touch事件
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
//任意取出一个touch对象
UITouch *touch = touches.anyObject;
beginPoint = [touch locationInView:self.view];
NSLog(@"mark = %d", mark);
if(mark == 0){
if (beginPoint.x<20) {
canMove=YES;
}else{
canMove=NO;
}
}
if(mark){
if (beginPoint.x]]]]>300) {
canMove=YES;
}else{
canMove=NO;
}
}
NSLog(@"触摸开始 %f,%f---",beginPoint.x,beginPoint.y);
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = touches.anyObject;
CGPoint movePoint = [touch locationInView:self.view];
NSLog(@"触摸滑动 %f",movePoint.x-beginPoint.x);
if (canMove && mark == 0) {
redView.frame=CGRectMake(-320+movePoint.x-beginPoint.x, 0, 320, 480);
}
if( canMove && mark == 1){
redView.frame=CGRectMake(movePoint.x - 320 , 0, 320, 480);
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"触摸结束");
UITouch *touch = touches.anyObject;
CGPoint endPoint = [touch locationInView:self.view];
if(mark == 0){
if ((endPoint.x-beginPoint.x)>200) {
[UIView animateWithDuration:0.25 animations:^{
redView.frame=CGRectMake(0, 0, 320, 480);
}];
mark = 1;
}else{
[UIView animateWithDuration:0.25 animations:^{
redView.frame=CGRectMake(-320, 0, 320, 480);
}];
}
}
else if(mark == 1){
NSLog(@"duanyulei");
if ((320 - endPoint.x)<20) {
[UIView animateWithDuration:0.25 animations:^{
redView.frame=CGRectMake(-320, 0, 320, 480);
}];
mark = 0;
}else{
[UIView animateWithDuration:0.25 animations:^{
redView.frame=CGRectMake(0, 0, 320, 480);
}];
}
}
}
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"触摸取消");
}
- (IBAction)showAlertView:(id)sender;
@property (weak, nonatomic) IBOutlet UIButton *showActionSheet;
- (IBAction)showActionSheet:(id)sender;
@end
@implementation QFViewController{
UIAlertView *alertView;
UIActionSheet *actionSheet;
}
- (void)viewDidLoad
{
[super viewDidLoad];
alertView=[[UIAlertView alloc]initWithTitle:@"通知" message:@"明天礼拜五了,大家晚上多多努力,争取在放假前把项目上架。" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil,nil];
actionSheet=[[UIActionSheet alloc]initWithTitle:@"你确定删除么?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"其他", nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)showAlertView:(id)sender {
[alertView show];
}
- (IBAction)showActionSheet:(id)sender {
[actionSheet showInView:self.view];
}
#pragma mark--
#pragma mark UIAlertView代理方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"点击了第%d个按键",buttonIndex);
switch (buttonIndex) {
case 0:
break;
default:
break;
}
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"点击了第%d个按键",buttonIndex);
switch (buttonIndex) {
case 0:
break;
default:
break;
}
}
IOS UI 第六篇:基本UI的更多相关文章
- IOS设计模式第六篇之适配器设计模式
版权声明:原创作品,谢绝转载!否则将追究法律责任. 那么怎么使用适配器设计模式呢? 这个之前提到的水平滚动的视图像这样: 为了开始实现他,我们创建一个新的继承与UIView的HorizontalScr ...
- IOS UI 第八篇:基本UI
实现图片的滚动,并且自动停止在每张图片上 - (void)viewDidLoad{ [super viewDidLoad]; UIScrollView *scrollView = [[U ...
- iOS进阶指南试读之UI篇
iOS进阶指南试读之UI篇 UI篇 UI是一个iOS开发工程师的基本功.怎么说?UI本质上就是你调用苹果提供给你的API来完成设计师的设计.所以,想提升UI的功力也很简单,没事就看看UIKit里的各个 ...
- 四核驱动的三维导航—淘宝新UI(设计篇)
前面有一篇博客说到了淘宝UWP的"四核驱动的三维导航—淘宝新UI(需求分析篇)",花了两周的时间实现了这个框架,然后又陆陆续续用了三周的时间完善它. 多窗口导航,与传统的导航方式的 ...
- 游戏模块分析总结(2)之UI、操作篇
转自:http://www.gameres.com/309812.html 游戏模块分析总结(2)之UI.操作篇 发布者: wuye | 发布时间: 2014-12-12 15:03| 评论数: 0 ...
- WPF案例 (六) 动态切换UI布局
原文:WPF案例 (六) 动态切换UI布局 这个Wpf示例对同一个界面支持以ListView或者CardView的布局方式呈现界面,使用控件ItemsControl绑定数据源,使用DataTempla ...
- 环信 之 iOS 客户端集成四:集成UI
在Podfile文件里加入 pod 'EaseUI', :git => 'https://github.com/easemob/easeui-ios-cocoapods.git' 然后在终端中的 ...
- WPF 精修篇 非UI进程后台更新UI进程
原文:WPF 精修篇 非UI进程后台更新UI进程 <Grid> <Grid.RowDefinitions> <RowDefinition Height="11* ...
- 第六章 consul UI
1.建立三个consul节点(一个server+两个client) 具体的过程见http://www.cnblogs.com/java-zhao/p/5375132.html 1)在终端下启动vagr ...
随机推荐
- Learn Python More
0, 看了一个python项目开源源码, 才知道现在这点python知识实在是弱爆了.. 尼玛就像学了2500个常用汉字, 然后要去理解"楚辞".. 代码如下, 解释一点一点从网上 ...
- 计数排序(C语言版本)
让我们来谈谈数的排序思维: 计数排序假定待排序的全部元素都是介于0到K之间的整数.计数排序使用一个额外的数组countArray.当中第i个元素是待排序数组array中值等于i的元素的个数.然后依据数 ...
- Codeforces 10C Digital Root 法冠军
主题链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<se ...
- Redis实现高并发分布式序列号
使用Redis实现高并发分布式序列号生成服务 序列号的构成 为建立良好的数据治理方案,作数据掌握.分析.统计.商业智能等用途,业务数据的编码制定通常都会遵循一定的规则,一般来讲,都会有自己的编码规则和 ...
- div元素上下左右居中
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- C#操作Xml:使用XmlReader读Xml
XmlDocument和XElement在读取Xml时要将整个Xml文档放到内存中去操作,这样做操作简单,但是很费内存和IO(可能是磁盘IO或者网络IO):而在有些场景下我们必须考虑尽可能节省内存和I ...
- 抓取数据同步备份hive
1:创建表 CREATE external TABLE `tbl_spider`( `url` string, `html` string ) partitioned by ( `site` stri ...
- 从头开始学JavaScript (六)——语句
原文:从头开始学JavaScript (六)--语句 一.条件分支语句:if 基本格式: if (<表达式1>){ <语句组1>}else if (<表达式2> ...
- java_代码注释风格
<?xml version="1.0" encoding="UTF-8" standalone="no"?><templa ...
- Linux基础正则表达式:grep,sed
先说明语系对正则表达式的影响 LANG=C:0,1,2,3,4...A,B,C,D...Z a b c d ... z LANG=zh_CN:0,1,2,3,4...a A b B c C ...