You are mixing Legos and K'Nex here.
Let's go to the documentation and see what is a valid diffuse content for SCNMaterial:
You can set a value for this property using any of the following
types:
A color (NSColor/UIColor or CGColor), specifying a uniform color for
the material’s surface
A number (NSNumber), specifying a uniform scalar value for the
material's surface (useful for physically based properties such as
metalness)
An image (NSImage/UIImage or CGImage), specifying a texture to be
mapped across the material’s surface
An NSString or NSURL object specifying the location of an image file
A video player (AVPlayer) or live video capture preview
(AVCaptureDevice, in iOS only)
A Core Animation layer (CALayer)
A texture (SKTexture, MDLTexture, MTLTexture, or GLKTextureInfo)
A SpriteKit scene (SKScene)
A specially formatted image or array of six images, specifying the
faces of a cube map
When you examine elements of a scene loaded from a file, this value is
always either a color object (of the NSColor or UIColor class,
according to platform) or an image object (of the NSImage or UIImage
class, according to platform). You can therefore use type
introspection (the isKind(of:) method in Objective-C, or the is
operator or let-as matching in Swift) to determine the type of the
material property’s contents.
https://developer.apple.com/documentation/scenekit/scnmaterialproperty/1395372-contents
Let us look at what UIView is:
class UIView : UIResponder
class UIResponder : NSObject
https://developer.apple.com/documentation/uikit/uiview
https://developer.apple.com/documentation/uikit/uiresponder
As you can see, UIView is not a valid type.
However, UIView does contain a CALayer
https://developer.apple.com/documentation/uikit/uiview/1622436-layer
So you should be able to use that to get what you need from your view:
func getCustomViewLayer() -> CALayer {
let view = UIView()
view.backgroundColor = .red
return view.layer
}