动画字体c语言,iOS开发--字体渐变动画

今天做了一个字体渐变出现的小动画,代码如下:

在controller中:

- (void) test{

_i=0;

self.view.backgroundColor= [UIColorwhiteColor];

self.testStr=@"生活需要你坦然的面对,坚强的撑起,因为下一个路口也许就是奇迹!";

UIView*m_mengbanView = [[UIViewalloc]init];

[self.viewaddSubview:m_mengbanView];

[m_mengbanViewmas_makeConstraints:^(MASConstraintMaker*make) {

make.left.mas_equalTo(self.view).mas_offset(limit5sW(13));

make.top.mas_equalTo(self.view).mas_offset(kScreenHeight-limit5sH(394/2.0) -limit5sH(13));

make.width.mas_equalTo(kScreenWidth-limit5sW(13) *2);

make.height.mas_equalTo(limit5sH(394/2.0));

}];

_textArray= [NSMutableArrayarray];

for(intj =1; j<=self.testStr.length; j++) {

NSRangerange =NSMakeRange(0, j);

NSString*str = [self.testStrsubstringWithRange:range];

[_textArrayaddObject:str];

}

CGFloatnocompare =0;

_dateDayLabel= [[UILabelalloc]initWithFrame:CGRectMake(CGRectGetWidth(self.view.frame) /2.0-limit5sW(55) -limit5sW(8),limit5sH(15),limit5sW(100),limit5sH(70) + nocompare)];

_dateDayLabel.adjustsFontSizeToFitWidth=YES;

_dateDayLabel.textAlignment=NSTextAlignmentCenter;

_dateDayLabel.textColor= [UIColorwhiteColor];

[m_mengbanViewaddSubview:_dateDayLabel];

_dateMoonLabel= [[UILabelalloc]initWithFrame:CGRectMake(CGRectGetMaxX(_dateDayLabel.frame) -limit5sW(13),CGRectGetMaxY(_dateDayLabel.frame) -limit5sH(20),limit5sW(120),limit5sH(20))];

_dateMoonLabel.textColor= [UIColorwhiteColor];

[m_mengbanViewaddSubview:_dateMoonLabel];

_imageTitleLabel= [[UILabelalloc]initWithFrame:CGRectMake(limit5sW(30),CGRectGetMaxY(_dateDayLabel.frame) +limit5sH(16),kScreenWidth-limitW(80),limitH(40))];

_imageTitleLabel.numberOfLines=0;

_imageTitleLabel.textColor= [UIColorredColor];

_imageTitleLabel.lineBreakMode=NSLineBreakByWordWrapping;

_imageTitleLabel.adjustsFontSizeToFitWidth=YES;

[m_mengbanViewaddSubview:_imageTitleLabel];

CGRectcontentL =_imageTitleLabel.frame;

if(self.testStr.length>19){

contentL.size.height+=10;

contentL.origin.y-=1;

}else{

contentL.origin.y-=6;

}

_imageTitleLabel.frame= contentL;

if(iPhone6){

CGRectcontentL =_imageTitleLabel.frame;

if(self.testStr.length>17){

contentL.size.height+=10;

contentL.origin.y-=1;

}else{

contentL.origin.y-=6;

}

_imageTitleLabel.frame= contentL;

CGRectrect1 =_dateMoonLabel.frame;

rect1.origin.x-=14;

_dateMoonLabel.frame= rect1;

CGRectrect2 =_dateDayLabel.frame;

rect2.origin.x-=24;

_dateDayLabel.frame= rect2;

}elseif(iPhone6P){

CGRectcontentL =_imageTitleLabel.frame;

if(self.testStr.length>17){

contentL.size.height+=10;

contentL.origin.y-=11;

}else{

contentL.origin.y-=7;

}

_imageTitleLabel.frame= contentL;

CGRectdateR =_dateDayLabel.frame;

dateR.origin.y-=30;

dateR.origin.x-=9;

dateR.size.height+=27;

_dateDayLabel.frame= dateR;

CGRectmoonR =_dateMoonLabel.frame;

moonR.origin.y-=2;

_dateMoonLabel.frame= moonR;

CGRectdataR =_dateDayLabel.frame;

dataR.origin.y+=limit5sH(14);

_dateDayLabel.frame= dataR;

}

_timer= [NSTimerscheduledTimerWithTimeInterval:0.2target:selfselector:@selector(print)userInfo:nilrepeats:YES];

}

- (void)print{

if(_i<_textarray.count>

_imageTitleLabel.text=_textArray[_i];

}

if(_i==_textArray.count) {

[_timerinvalidate];

_timer=nil;

}

_i+=1;

}

至此就可以实现字体渐变出现的小动画了,快来操作实现一下吧~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值