gpt4 book ai didi

ios - float 操作按钮的中心 UIButton 文本,如收件箱应用程序

转载 作者:搜寻专家 更新时间:2023-10-31 08:18:50 25 4
gpt4 key购买 nike

floatingButton = UIButton(x: blocx, y:blocy, width: imageSize, height: imageSize, target: self, action: "clickedFloatingButton")
floatingButton!.backgroundColor = CozyColors.StatCardSkip
floatingButton!.layer.cornerRadius = floatingButton!.frame.size.width / 2
floatingButton!.setTitle("+", forState: UIControlState.Normal)
floatingButton!.setTitleColor(CozyColors.ThemeWhite, forState: UIControlState.Normal)
floatingButton!.titleLabel?.font = UIFont(name: CozyStyles.ThemeFontName, size: imageSize*2/3)
view.addSubview(floatingButton!)

结果如下:

inbox app floating button action

如您所见,加号按钮未正确对齐到中心。如何在不添加 UILabel 作为 subview 的情况下将它放在中间?

最佳答案

试试这段代码:

    var floatingButton = UIButton(frame: CGRectMake(10, 20, 50, 50))
floatingButton.backgroundColor = UIColor.redColor()
floatingButton.layer.cornerRadius = floatingButton.frame.size.width / 2
floatingButton.setTitle("+", forState: UIControlState.Normal)
floatingButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
floatingButton.titleLabel?.font = UIFont(name: floatingButton.titleLabel!.font.familyName , size: 50)
floatingButton.titleEdgeInsets = UIEdgeInsetsMake(-10, 0, 0, 0)
view.addSubview(floatingButton)

关于ios - float 操作按钮的中心 UIButton 文本,如收件箱应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31025906/

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