没有得到正确的适用于iOS 11的UI按钮的圆形形状(Xcode 9)

问题描述:

我已经将一个按钮添加到导航栏作为自定义视图。它要求是圆形的。 使用下面的代码:没有得到正确的适用于iOS 11的UI按钮的圆形形状(Xcode 9)

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从设备

快照:

1

运行iOS 11设备快照:

enter image description here

如果你想,然后创建循环图您不需要设置clipsToBounds,但将masksToBounds设置为true。

+0

没有帮助。此外masksToBounds不是这里的要求。 –

使用这样的:

在这里,我改变了cornerRadiuswidth

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 

enter image description here

+0

试过了,仍然没有得到完美的圆形。 –

+0

尝试增加'width'并尝试。我检查了'iPad'和'iPhone'它为我工作。 –

+0

它是一个iOS 11设备,你检查了吗?它适用于在iOS 10上运行的所有设备,适用于我。问题出现在iOS 11设备上。 –