gpt4 book ai didi

ios - 为什么我的 UIBarButtonItem 没有标题?

转载 作者:行者123 更新时间:2023-11-28 12:52:01 25 4
gpt4 key购买 nike

我想制作一个带有圆形边框的 UIBarButtonItem。

    let postButton = UIButton(type: .Custom)
postButton.frame = CGRectMake(0, 0, 90, 30)
postButton.layer.borderColor = logoColor(0).CGColor
postButton.layer.borderWidth = CGFloat(3.0)
postButton.layer.cornerRadius = 4.0
postButton.clipsToBounds = true
postButton.titleLabel?.font = UIFont(name: "Lato-Bold", size: 10.0)
postButton.titleLabel?.textAlignment = .Center
postButton.titleLabel?.textColor = UIColor.blackColor()
postButton.setTitle("post", forState: .Normal)
postButtonBar = UIBarButtonItem(customView: postButton)

navigationItem.rightBarButtonItems = [ postButtonBar ]

我试过了,但结果是一个没有标题的红色轮廓按钮。

最佳答案

如果您正确构建按钮,您的代码将正常工作:

    let postButton = UIButton(type: .Custom)
postButton.frame = CGRectMake(0, 0, 90, 30)
postButton.layer.borderColor = UIColor.redColor().CGColor
postButton.layer.borderWidth = CGFloat(3.0)
postButton.layer.cornerRadius = 4.0
postButton.clipsToBounds = true
postButton.setTitle("post", forState: .Normal)
postButton.setTitleColor(UIColor.blackColor(), forState: .Normal)
postButton.titleLabel?.font = UIFont(name: "GillSans", size: 10.0)
postButton.setTitleColor(UIColor.grayColor(), forState: .Highlighted)
let postButtonBar = UIBarButtonItem(customView: postButton)

我替换了不同的字体,因为我没有你的字体...我还添加了灰色突出显示,以便按钮在点击时显示响应。

enter image description here

关于ios - 为什么我的 UIBarButtonItem 没有标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36228672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com