关键词:
【中文标题】属性标题未在 xib 文件的 UIButton 中加载自定义字体【英文标题】:attributed title not loading custom font in UIButton in xib file 【发布时间】:2015-05-08 20:46:14 【问题描述】:我正在努力解决这个问题,但不知道出了什么问题。我的一个界面构建器 xib 中有一个按钮,该按钮具有标题的属性字符串,该标题使用添加到我的应用程序中的自定义字体。界面生成器中的一切看起来都很好。
我 100% 确信我已将字体 (Montserrat) 正确加载到我的应用程序中。我可以在整个代码和控件的非属性标题中正确使用它,它工作正常。我还检查了调试器并正确列出了字体:
(lldb) po [UIFont familyNames]
<__NSCFArray 0x7bb34e20>(
Thonburi,
...
Montserrat,
...
Bodoni 72 Smallcaps
)
(lldb) po [UIFont fontNamesForFamilyName:@"Montserrat"]
<__NSCFArray 0x7be75400>(
Montserrat-Regular,
Montserrat-Bold
)
我还可以在文本编辑器的 xib 文件中看到,它看起来应该加载 Montserrat 的单词“got”:
<state key="normal">
<attributedString key="attributedTitle">
<fragment content="Already ">
<attributes>
<color key="NSColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<font key="NSFont" size="15" name="Helvetica"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
</attributes>
</fragment>
<fragment content="got">
<attributes>
<color key="NSColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<font key="NSFont" size="15" name="Montserrat-Bold"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
</attributes>
</fragment>
<fragment content=" an account? ">
<attributes>
<color key="NSColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<font key="NSFont" size="15" name="Helvetica"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
</attributes>
</fragment>
<fragment content="SIGN IN!">
<attributes>
<color key="NSColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<font key="NSFont" size="15" name="Helvetica-Bold"/>
<font key="NSOriginalFont" size="15" name="Helvetica-Bold"/>
<paragraphStyle key="NSParagraphStyle" alignment="center" lineBreakMode="wordWrapping" baseWritingDirection="natural"/>
</attributes>
</fragment>
</attributedString>
</state>
但我可以看到 iOS 在“got”一词中用“HelveticaNeueInterface-Regular”取代了我对“Montserrat-Bold”的使用。这是调试器的另一个摘录:
(lldb) po [self signInButton].titleLabel.attributedText
Already
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICTFont: 0x7bb41430> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 15.00pt";
NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
got
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICTFont: 0x7bb3ffe0> font-family: \".HelveticaNeueInterface-Regular\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
an account?
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICTFont: 0x7bb41430> font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 15.00pt";
NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
SIGN IN!
NSColor = "UIDeviceRGBColorSpace 0 0 0 1";
NSFont = "<UICTFont: 0x7bb3f6a0> font-family: \"Helvetica\"; font-weight: bold; font-style: normal; font-size: 15.00pt";
NSParagraphStyle = "Alignment 1, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (null), Lists (null), BaseWritingDirection -1, HyphenationFactor 0, TighteningFactor 0, HeaderLevel 0";
UILabels、模拟器或设备、iOS 7 或 8 上似乎也发生了同样的问题。但我可以在非属性标题上使用 Montserrat。在这一点上我真的很难过。有人遇到过这个问题吗?
谢谢, 暗里
【问题讨论】:
【参考方案1】:我认为这是一个错误
遇到了这个雷达http://openradar.appspot.com/18716979
【讨论】:
在从 XIB 加载的自定义视图中修改 UIButton 的标题标签
】在从XIB加载的自定义视图中修改UIButton的标题标签【英文标题】:ModifytheUIButton\'stitlelabelincustomviewloadedfromaXIB【发布时间】:2014-08-1213:00:09【问题描述】:在我的iOS项目中,我从一个XIB文件加载一个自定义视图,正如PaulSolt在他... 查看详情
按钮未在自定义 UIButton 中注册触摸
】按钮未在自定义UIButton中注册触摸【英文标题】:ButtonnotregisteringtouchesincustomUIButton【发布时间】:2018-01-2202:18:36【问题描述】:我尝试创建一个自定义UIButton,然后将一个普通按钮拖到我的视图中,并将Custom类属性设置为我创... 查看详情
我的 UIButton 在 xib 中发生了啥?
】我的UIButton在xib中发生了啥?【英文标题】:What\'sgoingonwithmyUIButtonsinaxib?我的UIButton在xib中发生了什么?【发布时间】:2011-08-1523:58:40【问题描述】:我有一组UIButtons(在xib中定义),它们的标签需要定期更新。在这些按钮的... 查看详情
UIButton 未在 iOS 中显示
】UIButton未在iOS中显示【英文标题】:UIButtonnotshowinginiOS【发布时间】:2011-08-1710:06:04【问题描述】:以下是显示工具栏按钮的代码。UIButtonmyButton=[UIButtonbuttonWithType:UIButtonTypeCustom];UIImage*myImage=[UIImageimageNamed:@"img1.png"];[myButtonsetBack... 查看详情
带有 .xib-File 的 @IBDesignable 类未在 Interface Builder 中呈现
...带有.xib-File的@IBDesignable类未在InterfaceBuilder中呈现【英文标题】:@IBDesignableclasswith.xib-FilenotrenderinginInterfaceBuilder【发布时间】:2017-06-0613:06:22【问题描述】:我有一个CustomClass.swift和一个CustomClass.xib。我希望XCode的InterfaceBuilder使... 查看详情
.xib 文件中创建的 UIButton 的 IBAction 或 [UIButton addTarget:action: forControlEvents:]?哪种方法更好?
】.xib文件中创建的UIButton的IBAction或[UIButtonaddTarget:action:forControlEvents:]?哪种方法更好?【英文标题】:IBActionor[UIButtonaddTarget:action:forControlEvents:]forUIButtoncreatedin.xibfile?Whichisthebetterapproach?【发布时间】:2012-07-1311:31:4 查看详情
UIButton 在 app.m 文件中不可用
】UIButton在app.m文件中不可用【英文标题】:UIButtonisnotAvailableinapp.mFile【发布时间】:2011-06-0514:59:52【问题描述】:我在app.xib文件中创建了一个UIButton。我将它连接到app.h文件中的“IBOutletidbutton;”。出于某种原因,当我开始输入a... 查看详情
在实例化之前从 XIB 文件中读取属性
】在实例化之前从XIB文件中读取属性【英文标题】:ReadpropertyfromXIBfilepriortoinstantiation【发布时间】:2011-10-0315:09:30【问题描述】:有几次我想在创建类的实例之前使用XIB文件中的值;想到的两个是:计算表格单元格的高度-表格... 查看详情
UIButton 大小与 xib 中的设置不同
】UIButton大小与xib中的设置不同【英文标题】:UIButtonsizeisnotassetinxib【发布时间】:2013-08-2013:11:07【问题描述】:我在InterfaceBuilder中使用自定义类型制作了UIButton,如下所示它的尺寸是但是,当我在Ratina4Simulator上运行它时,它显... 查看详情
如何在代码中创建自定义 UIButton 并在 xib 中使用它?
】如何在代码中创建自定义UIButton并在xib中使用它?【英文标题】:HowtocreateacustomUIButtonincodeanduseitinaxib?【发布时间】:2014-03-2600:31:44【问题描述】:我有一个继承自UIButton的类MyButton:UIButton。我在MyButton的initWithFrame(唯一的构造... 查看详情
如何批量编辑/重构 XIB 文件的属性?
】如何批量编辑/重构XIB文件的属性?【英文标题】:Howtoedit/refactorpropertiesofXIBfilesinbulk?【发布时间】:2012-09-1811:52:23【问题描述】:我的一个大项目是客户只是希望更改整个应用程序中的主要字体。代码分配的字体非常简单(... 查看详情
组件属性未在 innerHTML html 中呈现
】组件属性未在innerHTMLhtml中呈现【英文标题】:ComponentpropertynotrenderingintheinnerHTMLhtml【发布时间】:2022-01-2006:39:37【问题描述】:我在innerHTML的帮助下将一个svg文件渲染到我的组件中。我的svg文件有一些在我的组件中定义和设置... 查看详情
在目标c中单击UIButton更改图像[重复]
】在目标c中单击UIButton更改图像[重复]【英文标题】:changeimageonclickofUIButtoninobjectivec[duplicate]【发布时间】:2012-01-1006:36:52【问题描述】:可能重复:changeimageonclickofbuttoninobjectivec我在我的.xib文件中拖动了3个按钮,最初我使用属... 查看详情
UIbutton 未在 UITableViewCell 中更新其标记值
】UIbutton未在UITableViewCell中更新其标记值【英文标题】:UIbuttonnotupdatingitstagvalueinUITableViewCell【发布时间】:2013-04-1306:05:30【问题描述】:我有一个表格视图,我正在其中加载一些UIButtons并给它们动态标签。但是标签=0没有为UIButt... 查看详情
静态 UITableView 未在内容视图中显示带有子视图(UIButton、UISlider 等)的单元格
】静态UITableView未在内容视图中显示带有子视图(UIButton、UISlider等)的单元格【英文标题】:StaticUITableViewnotshowingcellswithsubviews(UIButton,UISlideretc.)inContentView【发布时间】:2014-09-0415:38:48【问题描述】:我遇到了Xcode的一个特殊问... 查看详情
强制退出后,带有堆栈视图的 Xcode 7 xib 未在界面生成器中显示
...后,带有堆栈视图的Xcode7xib未在界面生成器中显示【英文标题】:Xcode7xibwithstackviewsnotdisplayingininterfacebuilderafterforcequit【发布时间】:2015-11-1109:04:48【问题描述】:我在一个空的xib中创建了一个自定义单元格。当我正在处理它时... 查看详情
具有自定义图标大小的 UIButton 图像
】具有自定义图标大小的UIButton图像【英文标题】:UIButtonimagewithcustomiconsize【发布时间】:2013-08-1308:55:24【问题描述】:如果我在xib文件中有UIButton。是否可以在xib文件中设置具有自定义图标大小的每个图标按钮?es。我有一张40... 查看详情
具有目标操作的单元格上的 iOS UIButton,单元格未在 (id)sender 中更新
】具有目标操作的单元格上的iOSUIButton,单元格未在(id)sender中更新【英文标题】:iOSUIButtononcellwithtargetaction,cellnotupdatedin(id)sender【发布时间】:2013-11-1210:42:29【问题描述】:我有UIImage内容的自定义单元格UIButton,目标操作选择器... 查看详情