UILabel文字滚动
2015-07-23 11:26
519 查看
-(void)viewDidLoad
{
timer = [[NSTimer alloc] init];
mainsco = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
mainsco.backgroundColor = [UIColor clearColor];
[bgView addSubview:mainsco];
//显示广告内容
noticeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
noticeLabel.numberOfLines = 0;
noticeLabel.font = [UIFont systemFontOfSize:13.0f];
noticeLabel.backgroundColor = [UIColor clearColor];
[mainsco addSubview:noticeLabel];
noticeLabel.text =[dic valueForKey:@"Bulletin"];
noticeSize = [ [dic valueForKey:@"Bulletin"] sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(180, 20000000)];
//所有文字显示在一行所占的高度
size1 = [[dic valueForKey:@"Bulletin"] sizeWithFont:[UIFont systemFontOfSize:13.0f]];
mainsco.contentSize = CGSizeMake(180, noticeSize.height);
mainsco.showsVerticalScrollIndicator = NO;
//根据文字的多少设置label的宽高,但底层的scrollview只显示一行内容的高度
noticeLabel.frame = CGRectMake(0, 0, 180, noticeSize.height);
mainsco.frame =CGRectMake(116, 77, 180, size1.height);
if (noticeSize.height>size1.height)
{
//如果文字大于一行就开始滚动,否则停止timer
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(time) userInfo:self repeats:YES];
}else{
[timer invalidate];
}
}
//滚动的方法
-(void)time
{
//oldy用来记录上一次scrollview滚动的位置
mainsco.contentOffset = CGPointMake(0, oldy);
if (oldy>noticeSize.height-1) {
oldy = 0;
}else
oldy++;//设置每次滚动的高度,即几个像素
}
{
timer = [[NSTimer alloc] init];
mainsco = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
mainsco.backgroundColor = [UIColor clearColor];
[bgView addSubview:mainsco];
//显示广告内容
noticeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
noticeLabel.numberOfLines = 0;
noticeLabel.font = [UIFont systemFontOfSize:13.0f];
noticeLabel.backgroundColor = [UIColor clearColor];
[mainsco addSubview:noticeLabel];
noticeLabel.text =[dic valueForKey:@"Bulletin"];
noticeSize = [ [dic valueForKey:@"Bulletin"] sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(180, 20000000)];
//所有文字显示在一行所占的高度
size1 = [[dic valueForKey:@"Bulletin"] sizeWithFont:[UIFont systemFontOfSize:13.0f]];
mainsco.contentSize = CGSizeMake(180, noticeSize.height);
mainsco.showsVerticalScrollIndicator = NO;
//根据文字的多少设置label的宽高,但底层的scrollview只显示一行内容的高度
noticeLabel.frame = CGRectMake(0, 0, 180, noticeSize.height);
mainsco.frame =CGRectMake(116, 77, 180, size1.height);
if (noticeSize.height>size1.height)
{
//如果文字大于一行就开始滚动,否则停止timer
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(time) userInfo:self repeats:YES];
}else{
[timer invalidate];
}
}
//滚动的方法
-(void)time
{
//oldy用来记录上一次scrollview滚动的位置
mainsco.contentOffset = CGPointMake(0, oldy);
if (oldy>noticeSize.height-1) {
oldy = 0;
}else
oldy++;//设置每次滚动的高度,即几个像素
}
相关文章推荐
- 如何修改 UINavigationController、UINavigationBar 中 navigationItem 左侧 “返回” 按钮的名称
- UGUI之CanvasScaler的正确用法
- 在 UIViewController 中手动增加 TableView 出现 Type 'SomeViewController' does not confirm to protocol 'UITableViewDataSource' 问题的解决办法
- performSegueWithIdentifier 不生效的解决办法
- easyui 动态选项卡
- POJ 3061 Subsequence(尺取法)
- HDU 5288 OO’s Sequence(2015多校联合)
- select option如果里面不写value值,默认提交<option></option>中间的值
- Codeforces Round #313 (Div. 2) A.B,C,D,E Currency System in Geraldion Gerald is into Art Gerald's Hexagon Equivalent Strings
- LinearLayout布局属性难点
- 1017. Queueing at Bank (25)
- android多分辨率多屏幕密度下UI适配方案
- Android提高(15)——第五章 解析Android中更新UI的几种方式
- ios上 更改 状态栏(UIStatusBar)的颜色,你值得一看、收藏
- UITableView 当滚动的时候会有多出的空白,去掉空白的方法
- AutoLayout 根据文字、图片自动计算 UITableViewCell 高度
- iOS7 UITableView Row Height Estimation
- Hdu 5288 OO’s Sequence 2015多小联赛A题
- 判断UITableView滚动是否到底
- UIAlertView 提示弹窗