我已经在网上寻找加粗NSString的方法,要么它不在那里,要么我找不到它。我只是想大胆NSString的字,但到目前为止,我所做的是不是沃金:绑定一个nsstring
NSString *player1Name = [[UIFont boldSystemFontOfSize:12] fontName];
我一直依靠这使“player1Name”大胆,但它并没有在所有的工作。提前
感谢的人谁帮助我找出解决办法: 当我运行它,我得到这个。
我已经在网上寻找加粗NSString的方法,要么它不在那里,要么我找不到它。我只是想大胆NSString的字,但到目前为止,我所做的是不是沃金:绑定一个nsstring
NSString *player1Name = [[UIFont boldSystemFontOfSize:12] fontName];
我一直依靠这使“player1Name”大胆,但它并没有在所有的工作。提前
感谢的人谁帮助我找出解决办法: 当我运行它,我得到这个。
试试这个:
NSString *boldFontName = [[UIFont boldSystemFontOfSize:12] fontName];
NSString *yourString = ...;
NSRange boldedRange = NSMakeRange(2, 4);
NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:yourString];
[attrString beginEditing];
[attrString addAttribute:kCTFontAttributeName
value:boldFontName
range:boldedRange];
[attrString endEditing];
你不能让NSString的大胆:
NSString *myString = @"My string!";
NSAttributedString *myBoldString = [[NSAttributedString alloc] initWithString:myString
attributes:@{ NSFontAttributeName: [UIFont boldSystemFontOfSize:35.0] }];
您也可以为特定的文本等设定的范围内。除此之外,您可以将UILabel文本变为粗体。因为UILabels用于UI表示& NSStrings只是对象。所以,让你的UILabel大胆
[infoLabel setFont:[UIFont boldSystemFontOfSize:16]];
你不能大胆一的NSString ...尝试NSAttributedString ...
NSAttributedString *player1Name = [[NSAttributedString alloc] initWithString:@"name" attributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:12]}];
的fontName是UIFont
属性返回字体名称HelveticaNeueInterface-MediumP4
我试过这个....但它没有出来作为粗体 –
直到你将它设置在屏幕上的UI元素上的“属性文本”(而不是“文本”)属性中才会看到它。比如UILabel,UITextField,UITextView ......你把它放在哪里? –
你想要在uilabel中显示nsstring或其他? – kb920
NSString只是一串字符,没有属性,你可以用很多不同的方式显示粗体字符串,但最简单的是使用支持NSAttrebutedString的东西... –
使用NSAttributedString * player1Name = [[NSAttributedString alloc] initWithString: @“TEST_STRING”属性:@ {NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}]; – nikhil84