没有为iOS 11(Xcode 9)获取正确的UI按钮圆形

没有为iOS 11(Xcode 9)获取正确的UI按钮圆形,xcode,uibarbuttonitem,ios11,swift4,Xcode,Uibarbuttonitem,Ios11,Swift4,我在导航栏中添加了一个按钮作为自定义视图。它要求是圆形的。 使用以下代码: let infoButton = UIButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24)) infoButton.setTitle("₹", for: .normal) infoButton.layer.cornerRadius = 12 infoButton.clipsToBounds = true infoButton

我在导航栏中添加了一个按钮作为自定义视图。它要求是圆形的。 使用以下代码:

    let infoButton = UIButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
    infoButton.setTitle("₹", for: .normal)
    infoButton.layer.cornerRadius = 12
    infoButton.clipsToBounds = true
    infoButton.layer.borderWidth = 1.5

    let infoItem = UIBarButtonItem(customView: infoButton)
    navigationItem.rightBarButtonItems = [infoItem]
到目前为止,它一直运行良好,但在iOS 11设备中没有得到适当的圆形

运行在iOS 10上的设备的快照:

运行在iOS 11上的设备的快照:


如果要创建循环视图,则不需要设置clipsToBounds,而是需要将masksToBounds设置为true。

如果要创建循环视图,则不需要设置clipsToBounds,而是需要将masksToBounds设置为true。

如下使用:

在这里,我更改了
拐角半径
宽度

let infoButton = UIButton(frame: CGRect(x: 0, y: 0, width: 34, height: 24))
infoButton.setTitle("₹", for: .normal)
infoButton.layer.cornerRadius = infoButton.bounds.size.width / 2
infoButton.clipsToBounds = true
infoButton.layer.borderWidth = 1.5

像这样使用:

在这里,我更改了
拐角半径
宽度

let infoButton = UIButton(frame: CGRect(x: 0, y: 0, width: 34, height: 24))
infoButton.setTitle("₹", for: .normal)
infoButton.layer.cornerRadius = infoButton.bounds.size.width / 2
infoButton.clipsToBounds = true
infoButton.layer.borderWidth = 1.5

没有帮助。此外,这里不需要masksToBounds。没有帮助。这里也不需要masksToBounds。尝试过,仍然没有得到完美的圆形。尝试增加
宽度
并尝试。我签入了iPad和iPhone它对我有用。你在哪里签的是iOS 11设备?对于我来说,在所有运行iOS 10的设备上都可以正常工作。问题出现在iOS 11设备中。是的,我正在iOS 11上检查。请检查我从iOS 11设备上传的结果。尝试了,仍然没有得到完美的圆形。尝试增加
宽度
并尝试。我签入了iPad
和iPhone
它对我有用。你在哪里签的是iOS 11设备?对于我来说,在所有运行iOS 10的设备上都可以正常工作。问题在iOS 11设备中。是的,我正在iOS 11上检查。请检查我从iOS 11设备上载的结果。