【问题标题】:How to make a rounded oval button?如何制作一个圆形的椭圆形按钮?
【发布时间】:2017-03-04 06:47:25
【问题描述】:

我的目标是让我的按钮看起来像这样:

减去按钮周围的黑边。

在阅读了很多帖子后,我看到大多数解决方案都说要使用

layer.cornerRadius = 10.0

当我这样做时,我会得到:

它使边缘变得圆润,但没有给我想要的目标。

有什么建议吗?

【问题讨论】:

    标签: ios swift button rounded-corners


    【解决方案1】:

    斯威夫特 3

    myButton.layer.cornerRadius = myButton.frame.height / 2
    
    myButton.backgroundColor = UIColor.blue
    myButton.clipsToBounds = true
    myButton.tintColor = UIColor.white
    myButton.setTitle("Connect With Facebook", for: .normal)
    

    【讨论】:

    • 但是如果我把它放在我的视图中,框架还没有更新,所以它有一个稍微不正确的角半径......
    【解决方案2】:

    你可以这样做(例如,如果你的按钮被称为按钮):

    button.layer.cornerRadius = button.bounds.size.height / 2.0
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-02-27
      • 2012-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多