Skip to content
Tuszy edited this page May 29, 2011 · 4 revisions

Documentation

How to add MTLabel to your own project

To include MTLabel in your project:

  1. Open MTLabel.xcodeproj file
  2. Drag and drop header and implementation file of class MTLabel and copy it into your own project
  3. Include CoreText framework. If you're using xcode 3.x add new file->existing frameworks and find CoreText in there. In xcode 4, click on the project file, go to your app target, select Build Phases, then Link Binary With Libraries disclosure triangle and finally click on the + button to find CoreText framework inside.
  4. You're done!

Usage

The most simple way is to use one of the convenient constructors.

     MTLabel *label = [MTLabel labelWithFrame:CGRectMake(20, 150, 250, 70) 
                                      andText:@"Hello!"];
     [self.view addSubview:label];

You can go ahead, and customize it by adding your own font, text alignment, line spacing or font color

     MTLabel *label = [MTLabel labelWithFrame:CGRectMake(20, 150, 250, 70) 
                                      andText:@"Hello!"];
     [label setTextAlignment:MTLabelTextAlignmentCenter];
     [label setFont:[UIFont boldSystemFontOfSize:15]];
     [label setFontColor:[UIColor blueColor]];
     [label setLineHeight:20];
     [self.view addSubview:label];

if you want the label to automatically adjust its height based on the text, just call the setResizeToFitText: method

     MTLabel *label = [MTLabel labelWithFrame:CGRectMake(20, 150, 250, 70) 
                                      andText:@"Hello!"];
     [label setTextAlignment:MTLabelTextAlignmentCenter];
     [label setFont:[UIFont boldSystemFontOfSize:15]];
     [label setFontColor:[UIColor blueColor]];
     [label setLineHeight:20];
     [label setResizeToFitText:YES];
     [self.view addSubview:label];

As you can see, it works pretty much like UILabel does. For detailed usage information, please check out the example app. Feel free to contact me if you have any questions.

Clone this wiki locally