I’m trying to make a project with simple implementations of UIKit views as demos:
Objc Views.zip (2.6 KB)
And so far I’ve got the two views already demonstrated in @jfperusse’s original demo, but I’m having trouble doing more.
For example I’m stumbling over the most basic one of all—the simple UIView. I don’t seem to get any errors when I instantiate it, but I can’t see it. I tried to set its backgroundColor property but I got told something about not being able to find the key path or something like that.
Hi @UberGoober!
UIView.backgroundColor is a UIColor (see backgroundColor | Apple Developer Documentation) and not a CGColor.
objc.color is used to create a CGColor, but the Codea Color can automatically be converted to a UIColor.
If you use the following, you should be able to see your basic UIView:
plainView.backgroundColor = color(255, 255, 255, 255)
Hope this helps!
1 Like
I could have sworn I tried that combination of adjustments before, but I must not have because it works now. Thanks so much!
With that cleared up, here’s another instance where I got the same error:
insetsType = objc.class("UIEdgeInsets")
insets = insetsType()
insets.top, insets.left, insets.bottom, insets.right = 30, 30, 30, 30
uiTextView.textContainerInset = insets
I’m trying to apply some insets to the text view, and it doesn’t work, and I get this warning in the output:
Exception invoking setValue:forKeyPath:, verify the arguments.
@UberGoober objc.class is used to create new classes in Objective-C, not to instantiate existing ones. I believe there might not be a way to create or modify UIEdgeInsets at the moment, but I’ll look into this and keep you posted!
Oh ok thanks for clarifying. I guess I mis-read the documentation.
@UberGoober It’s not available yet, but I’ve added objc.insets(top, left, bottom, right)
to create a UIEdgeInsets and confirmed it worked in your UITextView example.
uiTextView.textContainerInset = objc.insets(30, 30, 30, 30)
I’ll let you know when this is available in beta!
Wow, does this mean edge insets will be available for every UIView that supports them?