iOS 垂直方向跑马灯 循环滚动 多处高亮显示

由于业务需求,需要实现一个垂直滚动文本的跑马灯,没有办法只有自己去写一个动画效果,下面直接贴出代码。

MTAVerticalLoopView.h文件的代码如下:

 

//
//  UIVerticalLoopView.h
//  Jovi
//
//  Created by yuzhuo on 2016/11/23.
//  Copyright © 2016年 dianping.com. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "MTANewAdviseInfo.h"

@protocol VerticalLoopDelegate<NSObject>

- (void)didClickContentAtIndex:(NSInteger)index;

@end
typedef enum
{
    VerticalLoopDirectionBottom,
    VerticalLoopDirectionDown,
    
}VerticalLoopDirection;

@interface MTAVerticalLoopView : UIView
{
    
    // 创建两个label循环滚动
    UILabel *_firstContentLabel;
    UILabel *_secondContentLabel;
    
    UILabel *_firstclickLabel;
    UILabel *_secondclickLabel;
    // 记录
    int currentIndex;
    
}
/** 动画方向默认往上
 *  跑马灯动画时间
 */
@property(nonatomic) float verticalLoopAnimationDuration;
/**
 *  显示的内容(支持多条数据)
 */
@property(nonatomic, retain) NSMutableArray<MTANewAdviseInfo *> *data;
/**
 * loop方向(上下/右)
 */
@property(nonatomic) VerticalLoopDirection Direction;
@property (nonatomic, weak)id<VerticalLoopDelegate> loopDelegate;
/**
 *  开启
 */
-(void)start;

- (void)loopContentClick;

@end

 

 

 

 

 

MTAVerticalLoopView.m文件的代码如下:

 

//
//  UIVerticalLoopView.m
//  Jovi
//
//  Created by yuzhuo on 2016/11/23.
//  Copyright © 2016年 dianping.com. All rights reserved.
//

#import "MTAVerticalLoopView.h"

@implementation MTAVerticalLoopView
{
    BOOL _animating;
}

#pragma mark - lifecycle
- (id)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupView];
    }
    return self;
}

#pragma mark - private method
-(void)setupView {
    
    _firstclickLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width-50, 10, 50, 25)];
    _firstclickLabel.font = [UIFont systemFontOfSize:11.0];
    [_firstclickLabel.layer setBorderColor:[UIColor colorWithHexString:@"#ff6633"].CGColor];//边框颜色
    [_firstclickLabel.layer setMasksToBounds:YES];
    [_firstclickLabel.layer setCornerRadius:12.5];
    [_firstclickLabel.layer setBorderWidth:1.0];
    _firstclickLabel.textColor = [UIColor colorWithHexString:@"#ff6633"];
    _firstclickLabel.textAlignment = NSTextAlignmentCenter;
    
    _secondclickLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.size.width-50, self.frame.size.height+10, 50, 25)];
    _secondclickLabel.font = [UIFont systemFontOfSize:11.0];
    [_secondclickLabel.layer setBorderColor:[UIColor colorWithHexString:@"#ff6633"].CGColor];//边框颜色
    [_secondclickLabel.layer setMasksToBounds:YES];
    [_secondclickLabel.l
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值