iOS UI-Lable标签、NStimer定时器和RunLoop超级死循环
2015-12-23 13:31
399 查看
// 标签UILable -显示文字 // 1.创建标签 UILabel *lable = [[UILabel alloc] init]; // 2.设置标签的坐标和大小 [lable setFrame:CGRectMake(0,20, 375, 50)]; // 3.标签内容 lable.text = @""; // 设置字体 lable.font = [UIFont systemFontOfSize:20]; // 设置字体颜色 lable.textColor = [UIColor blackColor]; // 设置内容换行 lable.numberOfLines = 0; //设置圆角 lable.layer.cornerRadius = 10; lable.layer.masksToBounds = NO; // 设置标签内容居中 lable.textAlignment = NSTextAlignmentCenter; // 设置标签背景 lable.backgroundColor = [UIColor blackColor]; // 加载图片 UIImageView *tempView = [[UIImageView alloc] init]; [tempView setFrame:CGRectMake(255, 0, 120, 50)]; tempView.image = [UIImage imageNamed:@"1.png"]; // 4.在当前视图之上加载子视图 [self.view addSubview:lable]; [lable addSubview:tempView];
#import "ViewController.h" @interface ViewController () { NSTimer *timer; NSInteger length; } @property (weak, nonatomic) IBOutlet UILabel *lable; @end @implementation ViewController -(void) lableMove { if (self.lable.frame.origin.y>667) { length = -10; } else if (self.lable.frame.origin.y<0) { length = 10; } CGRect rect = self.lable.frame; rect.origin.y +=length; self.lable.frame = rect; if (self.lable.frame.origin.y>700) { [timer invalidate]; [self.lable removeFromSuperview]; } } - (void)viewDidLoad { [super viewDidLoad]; /* NSTimeInterval 计时器响应时间间隔 target:计时器的响应者 selector:计时器的响应方法 userInfo:nil repeats:计时器是否重复响应 */ length = 10; timer = [NSTimer timerWithTimeInterval:0.1 target:self selector:@selector(lableMove) userInfo:nil repeats:YES]; //将定时器插入runLoop(超级死循环)中 [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSRunLoopCommonModes]; }
相关文章推荐
- 19.制作自动切换滚动的图片轮播
- IOS学习笔记之UISwitch
- iOS UISearchDisplayController学习笔记
- 【ZSTU4215 2015年12月浙理工校赛 F】【Dijkstra最短路】Landlocked 到达海洋最少跨越国家数
- UI布局分析工具-视图工具(Hierarchy Viewer)
- 仿支付宝密码输入界面+随机键盘
- UITextField键盘类型
- UITextField键盘类型
- NGUI研究院之3D模型坐标转2D屏幕坐标-血条
- Handler-接受子线程数据更新UI主线程;非主线程通信--HandlerThread
- 317. Shortest Distance from All Buildings
- UGUI 制作Animation 死活都不播放的坑
- ios搜索栏 UISearchBarDelegate委托常用方法
- Arduino - RGB全彩LED模块
- UITextField与键盘returnSearch关联
- uefi与GPT
- 在iOS 8中使用UIAlertController
- iOS 在UILabel显示不同的字体和颜色
- 关于uitableviewcell的accessoryType属性
- UICollectionView的下拉刷新无法滑动