码迷,mamicode.com
首页 > 其他好文 > 详细

UILabel混色显示

时间:2014-06-26 16:57:59      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:style   class   blog   code   http   tar   

UILabel混色显示

bubuko.com,布布扣

 

效果:

bubuko.com,布布扣

bubuko.com,布布扣

bubuko.com,布布扣

源码:

//
//  RootViewController.m
//  ColorLabels
//
//  Copyright (c) 2014年 Y.X. All rights reserved.
//

#import "RootViewController.h"
#import "YXGCD.h"

@interface RootViewController ()

@property (nonatomic, strong)  UIView   *upView;
@property (nonatomic, strong)  UILabel  *upLabel;
@property (nonatomic, strong)  UIView   *downView;
@property (nonatomic, strong)  UILabel  *downLabel;

@property (nonatomic, strong)  GCDTimer *timer;

@end

@implementation RootViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    /*
给upView的frame值做动画才是label能够混色显示的核心 upView(红色背景) ===> upLabel(白色底字) | | | | | | | | downView(白色背景) ===> downLabel(红色底字) */ // 上面一层 { // 红色背景 _upView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 15)]; _upView.center = self.view.center; _upView.layer.cornerRadius = 2.f; _upView.backgroundColor = [UIColor redColor]; _upView.layer.masksToBounds = YES; // 核心(不让subview显示超出范围) [self.view addSubview:_upView]; // 白色底字 _upLabel = [[UILabel alloc] initWithFrame:_upView.bounds]; _upLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:10.f]; _upLabel.text = @"You Xian Ming No Zuo No Die"; _upLabel.textColor = [UIColor whiteColor]; _upLabel.textAlignment = NSTextAlignmentCenter; [_upView addSubview:_upLabel]; } // 下面一层 { // 白色背景 _downView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 15)]; _downView.center = self.view.center; _downView.layer.cornerRadius = 2.f; _downView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:_downView]; // 红色底字 _downLabel = [[UILabel alloc] initWithFrame:_downView.bounds]; _downLabel.textColor = [UIColor redColor]; _downLabel.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:10.f]; _downLabel.text = @"You Xian Ming No Zuo No Die"; _downLabel.textAlignment = NSTextAlignmentCenter; [_downView addSubview:_downLabel]; } // 显示上面一层 [self.view bringSubviewToFront:_upView]; // 给上面一层的frame值做动画 _timer = [[GCDTimer alloc] initInQueue:[GCDQueue mainQueue]]; [_timer event:^{ [UIView animateWithDuration:0.3f animations:^{ CGRect tmpRect = _upView.frame; tmpRect.size.width = arc4random()%200; _upView.frame = tmpRect; }]; } timeInterval:NSEC_PER_SEC]; [_timer start]; } @end

bubuko.com,布布扣

 

 

 

 

UILabel混色显示,布布扣,bubuko.com

UILabel混色显示

标签:style   class   blog   code   http   tar   

原文地址:http://www.cnblogs.com/YouXianMing/p/3808467.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!