-
Notifications
You must be signed in to change notification settings - Fork 23
Documentation
Tuszy edited this page May 29, 2011
·
4 revisions
To include MTLabel in your project:
- Open MTLabel.xcodeproj file
- Drag and drop header and implementation file of class MTLabel and copy it into your own project
- 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
, thenLink Binary With Libraries
disclosure triangle and finally click on the + button to find CoreText framework inside. - You're done!
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.