41 lines
1.2 KiB
Plaintext
41 lines
1.2 KiB
Plaintext
import {
|
|
UIButton,
|
|
UIControl,
|
|
UIImageView,
|
|
UIImage
|
|
} from "UIKit"
|
|
import { SVGKImage } from "SVGKit" assert { type: "implementationOnly" };
|
|
import { UTSComponent } from "DCloudUTSFoundation"
|
|
import { Data } from 'Assignables';
|
|
import { CALayer } from 'QuartzCore';
|
|
import { CGRect, CGSize } from 'CoreFoundation';
|
|
|
|
|
|
|
|
export class xSvgU {
|
|
$element : UniNativeViewElement;
|
|
targetView : UIImageView | null = null;
|
|
constructor(element : UniNativeViewElement) {
|
|
this.$element = element;
|
|
this.targetView = new UIImageView()
|
|
this.$element.bindIOSView(this.targetView!);
|
|
}
|
|
|
|
setImage(newval : string) {
|
|
if (newval != '') {
|
|
let url = UTSiOS.getResourcePath(newval)
|
|
// let width = (16).toInt();
|
|
// let height = (16).toInt();
|
|
// this.targetView!.frame = new CGRect(x = 0, y = 0, width = width, height = height);
|
|
const size:CGRect = this.targetView!.frame;
|
|
let svgURL = new URL(fileURLWithPath = url)
|
|
let svgData = UTSiOS.try(new Data(contentsOf = svgURL),"?")
|
|
if(svgData==null) return;
|
|
let svgImage = new SVGKImage(data = svgData!)
|
|
svgImage!.size = new CGSize(width= size.width, height= size.height)
|
|
this.targetView!.image = svgImage?.uiImage
|
|
}
|
|
}
|
|
|
|
}
|