Giter Club home page Giter Club logo

m80attributedlabel's Introduction

M80AttributedLabel

Another attributed label using CoreText 中文版本

Features

  • Multi-line Rich Text Display
  • Auto Link Detection and Custom Links Supported
  • Embedding Image and Custom Views
  • Following Properties Supported:
    • font
    • textColor
    • highlightColor
    • linkColor
    • underLineForLink
    • numbersOfLines (Truncates Last Line Supported)
    • textAlignment
    • lineBreakMode
    • lineSpacing
    • paragraphSpacing
    • shadowColor
    • shadowOffset
    • shadowBlur

System Requirement

  • iOS 7.0 or later
  • ARC required

Installation

Podfile

pod 'M80AttributedLabel'

Manually

  • git clone https://github.com/xiangwangfeng/M80AttributedLabel.git
  • Copy files in Class/M80AttributedLabel to your project
  • Add CoreText.framework to your target

Usage

Basic

M80AttributedLabel *label = [[M80AttributedLabel alloc]initWithFrame:CGRectZero];
    
label.text      = @"Hello M80AttributedLabel";
label.font      = [UIFont fontWithName:@"Zapfino" size:25];
label.textColor = M80RGB(0xFF9F00);
label.shadowColor = [UIColor grayColor];
label.shadowOffset= CGSizeMake(1, 1);
label.shadowBlur = 1;
    
label.frame     = CGRectInset(self.view.bounds,20,20);

[self.view addSubview:label];
   

Link

M80AttributedLabel *label = [[M80AttributedLabel alloc]initWithFrame:CGRectZero];
    
NSString *text  = @"The game which I current play is hearthstone,and its website is www.hearthstone.com.cn";
NSRange range   = [text rangeOfString:@"hearthstone"];
label.text      = text;
[label addCustomLink:[NSValue valueWithRange:range]
            forRange:range];
label.delegate = self;
    
label.frame     = CGRectInset(self.view.bounds,20,20);

[self.view addSubview:label];

Image

M80AttributedLabel *label = [[M80AttributedLabel alloc]initWithFrame:CGRectZero];
label.lineSpacing = 5.0;
    
[label appendImage:[UIImage imageNamed:@"avatar"] 
		    maxSize:CGSizeMake(40, 40)
       	  margin:UIEdgeInsetsZero
 	      alignment:M80ImageAlignmentBottom];
    
NSString *text  = @"say:\n有人问一位登山家为什么要去登山——谁都知道登山这件事既危险,又没什么实际的好处。[haha][haha][haha][haha]他回答道:“因为那座山峰在那里。”我喜欢这个答案,因为里面包含着幽默感——明明是自己想要登山,偏说是山在那里使他心里痒痒。除此之外,我还喜欢这位登山家干的事,没来由地往悬崖上爬。[haha][haha][haha]它会导致肌肉疼痛,还要冒摔出脑子的危险,所以一般人尽量避免爬山。[haha][haha][haha]用热力学的角度来看,这是个反熵的现象,所发趋害避利肯定反熵。";
    
//replace [haha] by image
NSArray *components = [text componentsSeparatedByString:@"[haha]"];
NSUInteger count = [components count];
for (NSUInteger i = 0; i < count; i++)
{
    [label appendText:[components objectAtIndex:i]];
    if (i != count - 1)
    {
        [label appendImage:[UIImage imageNamed:@"haha"]
                       maxSize:CGSizeMake(15, 15)
                        margin:UIEdgeInsetsZero
                     alignment:M80ImageAlignmentCenter];
    }
}
    
label.frame     = CGRectInset(self.view.bounds,20,20);
[self.view addSubview:label];
    
    

Attachemnt

M80AttributedLabel *label = [[M80AttributedLabel alloc]initWithFrame:CGRectZero];
    
for (NSInteger i = 0; i < 3; i++)
{
	[label appendText:@"Click the icon to fire event"];
	
	UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
	button setBackgroundImage:[UIImage imageNamed:@"play"] forState:UIControlStateNormal];
	[button addTarget:self
              action:@selector(buttonClicked:)
    forControlEvents:UIControlEventTouchUpInside];
    [button setBounds:CGRectMake(0, 0, 30, 30)];
    [button setTag:i];
    [label appendView:button];
        
    [label appendText:@"\n\n\n"];
}
    

label.frame     = CGRectInset(self.view.bounds,20,20);
[self.view addSubview:label];

Contact

License

M80AttributedLabel is available under the MIT license. See the LICENSE file for more info.

m80attributedlabel's People

Contributors

xiangwangfeng avatar timelessg avatar

Watchers

James Cloos avatar Ling Chen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.