Needless to say, directly on the code, very simple, are native, note that the label can not be used. Text, to use. attributedtext!!
#import "ViewController.h"
@interface Viewcontroller () <UITableViewDataSource,UITableViewDelegate>
{
Nsmutablearray *_fontarray;
}
@property (Weak, nonatomic) Iboutlet UITableView *tableview;
@end
@implementation Viewcontroller
-(void) Viewdidload {
[Super Viewdidload];
Self.tableView.rowHeight = 80.0f;
_fontarray = [[Nsmutablearray alloc] initwithcapacity:242];
For (NSString * familyname in [Uifont Familynames]) {
NSLog (@ "Font familyname =%@", familyname); * Output font Family section name
For (NSString * fontname in [Uifont Fontnamesforfamilyname:familyname]) {
NSLog (@ "%@", FontName);
[_fontarray Addobject:fontname];
}
}
}
-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section
{
return _fontarray.count;
}
-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath
{
static NSString *id = @ "Cell";
UITableViewCell *cell = [TableView dequeuereusablecellwithidentifier:id];
if (cell = = nil) {
cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id];
}
NSString * teststr = @ "It has words";
nsmutableattributedstring *str = [[Nsmutableattributedstring alloc] initwithstring:teststr];
[Str addattribute:nsforegroundcolorattributename value:[uicolor Bluecolor] Range:nsmakerange (0,3)];
[Str addattribute:nsforegroundcolorattributename value:[uicolor Redcolor] Range:nsmakerange (3,4)];
[Str addattribute:nsforegroundcolorattributename value:[uicolor Greencolor] Range:nsmakerange (7,4)];
[Str addattribute:nsfontattributename value:[uifont Fontwithname:_fontarray[indexpath.row] size:30] Range: Nsmakerange (5, 6)];
Cell.textLabel.attributedText = str;
Cell.detailTextLabel.text = [nsstring stringwithformat:@ "font name:%@", _fontarray[indexpath.row]];
return cell;
}
@end
Customize the font color and size of labels