Search code examples
iosswiftxcodeuiimageview

how to programmatically, in Swift, set an uiimageview to the xcode built-in applewatch icon image?


I like the watch icon you get when you use storyboard to add a UIIMAGEVIEW and set its Image attribute to the built-in "applewatch" icon.

But when I programmatically create a UIIMAGEVIEW how can I set it to that cool icon?

Here I add a 3rd party .png of a wrist band. But I want to use the built-in which looks best:

let imageName = "Wrist Band.png"
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image!)
imageView.frame = CGRect(x: 0, y: 0, width: 100, height: 200)
view.addSubview(imageView)

Solution

  • You seem to be talking about the SF symbol applewatch. You can get that (or any other SF symbol) by using UIImage(systemName:):

    UIImage(systemName: "applewatch")
    

    Notes:

    • The color of the watch depends on the tintColor of the image view
    • Available on iOS 14+