how to create uibutton with corner radius?
Generated on 8/8/2024
1 search
To create a UIButton with a corner radius, you can use the layer
property of the UIButton to set the cornerRadius
. Here's a simple example in Swift:
let button = UIButton(type: .system)
button.setTitle("My Button", for: .normal)
button.backgroundColor = .systemBlue
button.setTitleColor(.white, for: .normal)
button.frame = CGRect(x: 50, y: 50, width: 200, height: 50)
// Set the corner radius
button.layer.cornerRadius = 10
button.clipsToBounds = true
In this example, the cornerRadius
property is set to 10, which will round the corners of the button. The clipsToBounds
property is set to true
to ensure that the subviews are confined to the bounds of the button, which is necessary for the corner radius to be visible.
For more advanced button customization, you might want to look into sessions like Create custom hover effects in visionOS which discusses various effects and customizations you can apply to buttons and other UI elements.
Migrate your TVML app to SwiftUI
SwiftUI helps you build great apps on all Apple platforms and is the preferred toolkit for bringing your content into the living room with tvOS 18. Learn how to use SwiftUI to create familiar layouts and controls from TVMLKit, and get tips and best practices.
Meet the Contact Access Button
Learn about the new Contacts authorization modes and how to improve Contacts access in your app. Discover how to integrate the Contact Access Button into your app to share additional contacts on demand and provide an easier path to Contacts authorization. We’ll also cover Contacts security features and an alternative API to be used if the button isn’t appropriate for your app.
Create custom hover effects in visionOS
Learn how to develop custom hover effects that update views when people look at them. Find out how to build an expanding button effect that combines opacity, scale, and clip effects. Discover best practices for creating effects that are comfortable and respect people’s accessibility needs.