SwiftUI Creates a Circle (SCC)

SwiftUI provides an easy and efficient way to create user interfaces (UI) for iOS applications, including geometric shapes like circles. To create a circle, SwiftUI offers the Circle() element, which can be used directly without complex code. This element supports various modifiers such as frame, fill, overlay, and shadow to adjust the circle’s size, color, and visual effects. With SwiftUI’s declarative approach, you simply write what you want to display, and SwiftUI takes care of rendering the UI accordingly.

Moreover, circles created with Circle() in SwiftUI can be combined with other elements to form more complex UI compositions. For example, you can add a circle as the background of a button or stack several circles together for a unique visual effect. SwiftUI’s support for animations and interactivity also enables circles to dynamically change size, color, or position. These features make creating circles in SwiftUI flexible, easy, and enjoyable for iOS developers.

How can I quickly create a circle image?

My view controller does nothing..

profilPicture = UIImageView(frame: CGRectMake(0, 0, 100, 100))

Solution

import UIKit

class ViewController: UIViewController {
  @IBOutlet weak var image: UIImageView!

  override func viewDidLoad() {
    super.viewDidLoad()
    
    image.layer.borderWidth = 1
    image.layer.masksToBounds = false
    image.layer.borderColor = UIColor.black.cgColor
    image.layer.cornerRadius = image.frame.height/2
    image.clipsToBounds = true
}

If you want it in extension

import UIKit

extension UIImageView {
    
    func makeRounded() {
        
        layer.borderWidth = 1
        layer.masksToBounds = false
        layer.borderColor = UIColor.black.cgColor
        layer.cornerRadius = self.frame.height / 2
        clipsToBounds = true
    }
}

That's all you need


Post a Comment

Previous Next

نموذج الاتصال