dw怎么让文字滚动uilable里面的文字过长,dw怎么让文字滚动他滚动显示

BBFlashCtntLabel文件
#import &UIKit/UIKit.h&
typedef NS_ENUM(NSInteger, BBFlashCtntSpeed) {
& & BBFlashCtntSpeedSlow = -1,
& & BBFlashCtntSpeedMild,
& & BBFlashCtntSpeedFast
@interface BBFlashCtntLabel : UIView
@property (nonatomic, strong) NSString *
@property (nonatomic, strong) UIFont * & & & & // 默认:system(15)
@property (nonatomic, strong) UIColor *textC
@property (nonatomic, strong) NSAttributedString *attributedT
@property (nonatomic, assign) BBFlashCtntS
// 循环滚动次数(为0时无限滚动)
@property (nonatomic, assign) NSUInteger repeatC
@property (nonatomic, assign) CGFloat leastInnerG
- (void)reloadV
&BBFlashCtntLabel文件
#import "BBFlashCtntLabel.h"
@interface BBFlashCtntLabel()
& & BOOL moveN
@property (nonatomic, strong) UIView *innerC
@implementation BBFlashCtntLabel
- (void)awakeFromNib
& & [super awakeFromNib];
& & self.font = [UIFont systemFontOfSize:15];
& & self.textColor = [UIColor blackColor];
& & self.speed = BBFlashCtntSpeedM
& & self.repeatCount = 0;
& & self.leastInnerGap = 10.f;
& & self.clipsToBounds = YES;
& & rate = 80.f;
& & [self setup];
- (instancetype)initWithFrame:(CGRect)frame
& & if (self = [super initWithFrame:frame]) {
& & & & self.font = [UIFont systemFontOfSize:15];
& & & & self.textColor = [UIColor blackColor];
& & & & self.speed = BBFlashCtntSpeedM
& & & & self.repeatCount = 0;
& & & & self.leastInnerGap = 10.f;
& & & & self.clipsToBounds = YES;
& & & & [self setup];
- (void)setSpeed:(BBFlashCtntSpeed)speed
& & _speed =
& & switch (_speed) {
& & & & case BBFlashCtntSpeedFast:
& & & & & & rate = 90.;
& & & & & &
& & & & case BBFlashCtntSpeedMild:
& & & & & & rate = 75;
& & & & & &
& & & & case BBFlashCtntSpeedSlow:
& & & & & & rate = 40.;
& & & & & &
& & & & default:
& & & & & &
& & [self reloadView];
- (void)setLeastInnerGap:(CGFloat)leastInnerGap
& & _leastInnerGap = leastInnerG
& & [self reloadView];
- (void)setText:(NSString *)text
& & _text =
& & _attributedText =
& & [self reloadView];
- (void)setAttributedText:(NSAttributedString *)attributedText
& & _attributedText = [self setAttributedTextDefaultFont:attributedText];
& & _text =
& & [self reloadView];
- (NSAttributedString *)setAttributedTextDefaultFont:(NSAttributedString *)attrText
& & NSMutableAttributedString *rtn = [[NSMutableAttributedString alloc] initWithAttributedString:attrText];
& & void (^enumerateBlock)(id, NSRange, BOOL *) = ^(id value, NSRange range, BOOL *stop) {
& & & & if (!value || [value isKindOfClass:[NSNull class]]) {
& & & & & &
& & & & & & [rtn addAttribute:NSFontAttributeName
& & & & & & & & & & & & value:self.font
& & & & & & & & & & & & range:range];
& & [rtn enumerateAttribute:NSFontAttributeName
& & & & & & & & & & inRange:NSMakeRange(0, rtn.string.length)
& & & & & & & & & & options:0
&& & & & & & & & usingBlock:enumerateBlock];
- (void)setFont:(UIFont *)font
& & _font =
& & [self reloadView];
- (void)setTextColor:(UIColor *)textColor
& & _textColor = textC
& & [self reloadView];
- (void)setup
& & if (seted) {
& & self.innerContainer = [[UIView alloc] initWithFrame:self.bounds];
& & self.innerContainer.backgroundColor = [UIColor clearColor];
& & self.innerContainer.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleW
& & [self addSubview:self.innerContainer];
& & seted = YES;
- (void)reloadView
& & [self.innerContainer.layer removeAnimationForKey:@"move"];
& & for (UIView *sub in self.innerContainer.subviews) {
& & & & if ([sub isKindOfClass:[UILabel class]]) {
& & & & & & [sub removeFromSuperview];
& & CGFloat width = [self evaluateContentWidth];
& & moveNeed = width & self.bounds.size.
& & CGRect f = CGRectMake(0, 0, width, self.bounds.size.height);
& & UILabel *label = [[UILabel alloc] initWithFrame:f];
& & label.backgroundColor = [UIColor clearColor];
& & if (self.text) {
& & & & label.text = self.
& & & & label.textColor = self.textC
& & & & label.font = self.
& & } else {
& & & & label.attributedText = self.attributedT
& & [self.innerContainer addSubview:label];
& & if (moveNeed) {
& & & & CGRect f1 = CGRectMake(width + self.leastInnerGap, 0, width, f.size.height);
& & & & UILabel *next = [[UILabel alloc] initWithFrame:f1];
& & & & next.backgroundColor = [UIColor clearColor];
& & & & if (self.text) {
& & & & & & next.text = self.
& & & & & & next.textColor = self.textC
& & & & & & next.font = self.
& & & & } else {
& & & & & & next.attributedText = self.attributedT
& & & & [self.innerContainer addSubview:next];
& & & & CAKeyframeAnimation *moveAnimation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.x"];
& & & & moveAnimation.keyTimes = @[@0., @0.191, @0.868, @1.0];
& & & & moveAnimation.duration = width /
& & & & moveAnimation.values = @[@0, @0., @(- width - self.leastInnerGap)];
& & & & moveAnimation.repeatCount = self.repeatCount == 0 ? INT16_MAX : self.repeatC
& & & & moveAnimation.timingFunction = [CAMediaTimingFunction functionWithName:@"linear"];
& & & & [self.innerContainer.layer addAnimation:moveAnimation forKey:@"move"];
- (CGFloat)evaluateContentWidth
& & CGFloat width = 0.f;
& & NSStringDrawingOptions options = NSStringDrawingTruncatesLastVisibleLine |
& & NSStringDrawingUsesLineFragmentOrigin |
& & NSStringDrawingUsesFontL
& & if (_text.length & 0) {
& & & & NSDictionary *attr = @{NSFontAttributeName : self.font};
& & & & CGSize size = [_text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, self.bounds.size.height) options:options attributes:attr context:nil].
& & & & width = size.
& & } else if (_attributedText.length & 0) {
& & & & CGSize size = [_attributedText boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, self.bounds.size.height) options:options context:nil].
& & & & width = size.
&for (int i = 0; i & 5; i++) {
& & & & //利用循环从下至上添加5个lable
& & & & CGRect rect = CGRectMake(100, 450 - i * 105, 180, 100);
& & & & BBFlashCtntLabel *lbl = [[BBFlashCtntLabel alloc] initWithFrame:rect];
& & & & //设置文本框的背景颜色
& & & & lbl.backgroundColor = [UIColor lightGrayColor];
//& & & & lbl.leastInnerGap = 50.f;
& & & & //对第三个文本框进行设置
& & & & if (i % 3 == 0) {
& & & & & & //设置播放次数
& & & & & & lbl.repeatCount = 5;
& & & & & & //设置播放速度为 慢
& & & & & & lbl.speed = BBFlashCtntSpeedS
& & & & else if (i % 3 == 1) {
& & & & & & //设置第一 跟第四个文本框的播放速度为 中
& & & & & & lbl.speed = BBFlashCtntSpeedM
& & & & else {
& & & & & & //设置播放速度为 快
& & & & & & lbl.speed = BBFlashCtntSpeedF
& & & & NSString *str = @"测试文字。来来;&了哈哈?^_^abcdefg123456?";
& & & & if (i %2 == 0) {
& & & & & & lbl.text =
&& & & & & &
& & & & & & lbl.font = [UIFont systemFontOfSize:25];
&& & & & & &
& & & & & & lbl.textColor = [UIColor whiteColor];
& & & & } else {
&& & & & & &
& & & & & & NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:str];
& & & & & & //根据索引值改变文字的大小
& & & & & & [att addAttribute:NSFontAttributeName
& & & & & & & & & & & & value:[UIFont systemFontOfSize:25]
& & & & & & & & & & & & range:NSMakeRange(0, 5)];
&& & & & & &
& & & & & & [att addAttribute:NSFontAttributeName
& & & & & & & & & & & & value:[UIFont systemFontOfSize:17]
& & & & & & & & & & & & range:NSMakeRange(15, 5)];
& & & & & & //根据索引值给文字添加背景颜色
& & & & & & [att addAttribute:NSBackgroundColorAttributeName
& & & & & & & & & & & & value:[UIColor blueColor]
& & & & & & & & & & & & range:NSMakeRange(0, 15)];
& & & & & & //给文字添加颜色
& & & & & & [att addAttribute:NSForegroundColorAttributeName
& & & & & & & & & & & & value:[UIColor redColor]
& & & & & & & & & & & & range:NSMakeRange(8, 7)];
& & & & & & lbl.attributedText =
& & & & if (i == 0) {
& & & & & & lbl.textColor = [UIColor greenColor];
& & & & & & lbl.text = @"少量文字";
& & & & [self.view addSubview:lbl];
阅读(...) 评论()怎么让文字在点阵里滚动啊【51单片机吧】_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:51,837贴子:
怎么让文字在点阵里滚动啊收藏
怎么让文字在点阵里滚动啊
改变数据就行了
指针和数组的用法,改变指针地址就行
精通点阵文字的滚动显示,加我QQ
让前一个LED显示后一个LED状态啊
for 循环,大的控制滚动时间里面小的控制滚动字幕显示
楼主,请问一下怎么做,我做的是8x8的,遇到问题了?
登录百度帐号推荐应用下次自动登录
现在的位置:
& 综合 & 正文
UILable控件
让label自适应里面的文字,自动调整宽度和高度。
1、 UILabel 使用 NSString 显示文字------代码创建Label
//定义标签的位置和尺寸,位置:x=0.0f, y=0.0f ,尺寸:x=320.0f, y=30.0f
UILabel *Label = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 30.0f)];
//建立 NSString,定义其内容为“abc”
NSString *sampleText = [NSString stringWithFormat:@"abc"];
//使用UILabel Label 获取sampleText
Label.text = sampleT
//输出结果
NSLog(@“%@\n”,sampleText);
//在 View 的 subview 中加入标签
[self.view addSubview:Label];
//使用后释放Label
[Label release];
//设置显示文字
scoreLabel.text = @"我是Andy--清风";
//设置字体:粗体,正常的是 SystemFontOfSize,调用系统的字体配置
scoreLabel.font = [UIFont boldSystemFontOfSize:20];
//设置文字颜色,可以有多种颜色可以选择
scoreLabel.textColor = [UIColor orangeColor];
scoreLabel.textColor = [UIColor purpleColor];
//设置文字对齐位置,居左,居中,居右
scoreLabel.textAlignment = UITextAlignmentR
scoreLabel.textAlignment = UITextAlignmentC
//设置字体大小是否适应label宽度
scoreLabel.adjustsFontSizeToFitWidth = YES;
//设置label的行数,这个可以根据上节的UITextView自适应高度
scoreLabel.numberOfLines = 2;
//设置文本是否高亮和高亮时的颜色
scoreLabel.highlighted = YES;
scoreLabel.highlightedTextColor = [UIColor orangeColor];
//设置阴影的颜色和阴影的偏移位置
scoreLabel.shadowColor = [UIColor redColor];
scoreLabel.shadowOffset = CGSizeMake(1.0,1.0);
//设置是否能与用户进行交互
scoreLabel.userInteractionEnabled = YES;
//设置label中的文字是否可变,默认值是YES
scoreLabel.enabled = NO;
//设置文字过长时的显示格式
scoreLabel.lineBreakMode = UILineBreakModeMiddleT//截去中间
//设置背景色为透明
scoreLabel.backgroudColor=[UIColor clearColor];
2、 分类:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];这个frame是初设的,没关系,后面还会重新设置其size。[label setNumberOfLines:0];NSString *s = @"string......";UIFont *font = [UIFont fontWithName:@"Arial" size:12];CGSize size = CGSizeMake(320,2000);CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];[label setFrame:CGRectMake:(0,0, labelsize.width, labelsize.height)];[self.view addSubView:label];这样就可以对s赋值让其自动调整其大小了。其实宽度可以设置为固定,让其改高度更好。
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0,0,0,0)];这个frame是初设的,没关系,后面还会重新设置其size。
[label setNumberOfLines:0];
NSString *s = @"string......";
UIFont *font = [UIFont fontWithName:@"Arial" size:12];
CGSize size = CGSizeMake(320,2000);
CGSize labelsize = [s sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeWordWrap];
[label setFrame:CGRectMake:(0,0, labelsize.width, labelsize.height)];
[self.view addSubView:label];
这样就可以对s赋值让其自动调整其大小了。其实宽度可以设置为固定,让其改高度更好。
&&&&推荐文章:
【上篇】【下篇】

我要回帖

更多关于 怎么让网页文字滚动 的文章

 

随机推荐