导航栏标题字体颜色没有设置为RGB,但可以使用标准颜色



可以。它正确设置了字体和颜色:

[self.navigationController.navigationBar setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  COA_TITLE_FONT(17.0),
  NSFontAttributeName, [UIColor brownColor], NSForegroundColorAttributeName, nil]];

这会使标题变成白色——或者至少在有色背景下看起来是这样的:

[self.navigationController.navigationBar setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  COA_TITLE_FONT(17.0),
  NSFontAttributeName, [UIColor colorWithRed:62.0f green:116.0f blue:140.0f alpha:1.0f], NSForegroundColorAttributeName, nil]];

我在IB中广泛使用RGB来设置标签,按钮等,但不能以这种方式设置这个。我想知道它是不是色调不对,但是棕色看起来……布朗。

您需要使用RGB的十进制值。将所有的浮点数除以255。现在你将它设置为纯白色,因为它将>1的值读取为1.0f

[self.navigationController.navigationBar setTitleTextAttributes:
 [NSDictionary dictionaryWithObjectsAndKeys:
  COA_TITLE_FONT(17.0),
   NSFontAttributeName, [UIColor colorWithRed:62.0f/255.0f green:116.0f/255.0f blue:140.0f/255.0f alpha:1.0f], NSForegroundColorAttributeName, nil]];

最新更新