- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法将紧排空间添加到标签栏属性文本中。有问题的 UITabBar 是一个自定义的 tabBar,您可以在下面找到代码。
我正在使用“属性键”字典向项目标题添加属性,但我遇到了紧排空间问题。
class ProfileTabBar: UITabBar {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setStyle()
}
required override init(frame: CGRect) {
super.init(frame: frame)
self.setStyle()
}
func setStyle() {
self.tintColor = Style.shared.primary1
// Disable the default border
self.layer.borderWidth = 0.0
self.clipsToBounds = true
// Create a new bottom border
let bottomLine = CALayer()
let screenWidth = UIScreen.main.bounds.width
//let viewForFrame = self.superview ?? self
//let screenWidth = viewForFrame.bounds.width
bottomLine.frame = CGRect(x: 0.0, y: self.frame.height - 1, width: screenWidth, height: 2.0)
bottomLine.backgroundColor = UIColor(red: 235.0/255, green: 235.0/255, blue: 235.0/255, alpha: 1.0).cgColor
self.layer.addSublayer(bottomLine)
// Get the size of a single item
let markerSize = CGSize(width: screenWidth/CGFloat(self.items!.count), height: self.frame.height)
// Create the selection indicator
self.selectionIndicatorImage = UIImage().createSelectionIndicator(color: self.tintColor, size: markerSize , lineWidth: 3.0)
// Customizing the items
if let items = self.items {
for item in items {
item.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -15)
let attributes: [NSAttributedStringKey : Any] = [
NSAttributedStringKey.font: UIFont(name: Style.shared.fontBold.fontName, size: 14) as Any,
NSAttributedStringKey.kern: NSNumber(value: 1.0)
]
item.setTitleTextAttributes(attributes, for: .normal)
}
}
}
除了紧排外,所有属性都有效。我做错了什么?
最佳答案
这个问题很老了,还有一个更老的答案 here 。 UITabBarItem
外观似乎忽略了 NSAttributedString.Key.kern
。这给我们留下了一些选择。
子类 UITabBarItem
这并不容易,因为 UITabBarItem
继承自 UIBarItem
,它是一个 NSObject
不是 UIView
。
子类 UITabBar
这可以完成,但只需要一些紧排就需要大量工作。您必须使用 UIButton
而不是 UITabBarItem
以便应用 kern。
您可以在标题中使用 unicode 字符添加间距。这非常简单,只需几行代码就可以实现您正在寻找的间距。
U+0020
1/4 em
U+2004
1/3 em
U+2005
1/4 em
U+2006
1/6 em
U+2008
句号“.”的宽度
U+2009
1/5 em(有时是 1/6 em)
您可以在 Swift 中的 String
中使用 unicode 字符,例如 "\u{2006}"
。这意味着我们可以在 tabBarItem 标题中的所有字符之间插入一个小空格。像这样:
extension String {
var withOneSixthEmSpacing: String {
let letters = Array(self)
return letters.map { String($0) + "\u{2006}" }.joined()
}
将其用于我们的 tabBarItems:
self.navigationController.tabBarItem = UITabBarItem(
title: "Home".withOneSixthEmSpacing,
image: homeImage,
selectedImage: homeSelectedImage
)
代替:
关于iOS swift : add kern space in the tab bar text,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50676585/
每当我点击UIImagePickerController它给了我这个错误..我已经尝试了其他链接的解决方案,但无法删除它。不明白为什么会发生这个错误?????? 2016-04-02 13:27:10
如果我通过 -0.36,字距调整不起作用,如果我从 iPhone 截取屏幕截图并与设计进行比较,则字符串与长度不匹配。 func addCharacterSpacing(kernValue: Doub
我对 mongodb 很陌生。通过以下方式安装后:brew intall mongodb 然后在终端中键入 mongod,错误抛出:kern.sched unavailable。 我使用的是 mac
目前我可以在 kern.log 中找到这样的条目: [6516247.445846] ex3.x[30901]: segfault at 0 ip 0000000000400564 sp 00007f
根据NSAttributedString UIKit Additions Reference : NSKernAttributeName The value of this attribute is
我当前正在尝试编译这个简单的代码: #include int main(int argc, char *argv[]) { GtkWidget *window; gtk_init(&argc, &a
我已经完成了自签名代码协同设计——但不确定为什么 vm_write 会失败。(我使用的是 10.6.6) 试图找出使它工作所缺少的东西——我感谢对这个问题的一些帮助。 #include #inclu
我已经创建了一些代码来将内存写入系统上的另一个进程,但是 mach_vm_write() 失败并出现“(os/kern) 无效地址”错误,尽管地址看似有效。我的代码如下。 if ((kret = ta
当使用dmesg 或cat/var/log/kern.log 命令转储内核日志时,我们可以看到如下内容: [ 22.949049] random: nonblocking pool is init
我需要为 UILabel 显示的文本设置两个属性:字母间距 (kern) 及其删除线样式。根据 NSAttributedStringKey 文档,我为 UILabel 创建了以下扩展: extensi
我正在使用应用于 CATextLayer 的自定义字体。我正在使用此处找到的教程和示例代码。 http://www.freetimestudios.com/2010/09/13/custom-font
我尝试使用 line_profiler 模块来获取 Python 文件的逐行配置文件。这是我到目前为止所做的: 1) 从 pypi 安装 line_profiler通过使用 .exe 文件(我在 Wi
登录到我的 Ubuntu 机器,我收到一条警告说我的磁盘空间不足。回溯,我发现是系统日志,尤其是 kern.log(s) 占用了我的 1TB 磁盘。 -rw-r----- 1 syslog adm 2
在python中如何获取sysctl kern.module_path的值? 我知道我可以使用 popen 将 sysctl(1) 作为子进程打开。有更好的办法吗? 最佳答案 我认为你最好的选择是 s
在尝试查看系统上的 gcc 版本时,我收到以下消息 gcc --version gcc: warning: couldn’t understand kern.osversion ‘14.5.0 gcc
我正在修改 kvm 模块,并在内核代码中添加了 printk 语句。运行虚拟机后,printk 为我提供了错误地址和有关 guest 操作系统的其他信息。 我需要从这个信息中生成统计信息。当我使用 d
我无法将紧排空间添加到标签栏属性文本中。有问题的 UITabBar 是一个自定义的 tabBar,您可以在下面找到代码。 我正在使用“属性键”字典向项目标题添加属性,但我遇到了紧排空间问题。 clas
我需要支持通过 Interface Builder (IB) 添加的一些标签的自定义字距调整。自定义类在 IB 中的标签上设置,文本也在那里设置。尝试使用 attributedText 属性覆盖 te
CDirScan 函数 NextL 引发“Main Panic KERN-EXEC 0”,如果它没有立即被调用 SetScanDataL()(即,如果它在另一个事件之后在同一个事件对象中稍后被调用)
目前 Apple 提供了访问字体表中数据的函数,例如 CTFontCopyTable .我正在使用它在可用时从字体中解析信息(字距调整等)。是否有任何类似的方法可以在 Windows 上按字体提取相同
我是一名优秀的程序员,十分优秀!