简体   繁体   中英

How can I create a UIImageView programmatically in NativeScript?

I am building a NativeScript-Vue application and I am trying to add an image to the large iOS navigation bar. An example can be found here:

Add a button to large title navigation bar

And, exactly like the linked question I need the image to only be visible when the large titles are enabled. Fortunately there is a linked medium article which provides the solution.

However, I am having problems creating the UIImageView programmatically. Once I have managed to do this I think I will be able to convert the rest of the code.

I have tried the following:

  1. Using the UIImageView constructor, but it required arguments in an unknown form
  2. Creating a NS-Vue Image, but the nativeView property was undefined
  3. Trying to hoist an already mounted image, but NativeScript threw errors

The NativeScript-Vue element that looks exactly what I need is as follows (however, I need to create the UIImageView with TypeScript instead):

<Image src="~/assets/images/users/eliottrobson.png" width="26" height="26"/>

This is the swift equivalent I am struggling to convert

private let imageView = UIImageView(image: UIImage(named: "image_name"))

In case anyone else struggles with this, the following works for me:

let image = UIImage.imageNamed("app/assets/images/users/eliottrobson.png");
let imageView = new UIImageView({ image: image });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM