I want to match the size of "yellow_noise.png" to the size of the "pickedImage" from the UIImagePickerController. What should I do?
originalImageView.image = pickedImage
overayImageView.image = UIImage(named:"yellow_noise.png")
Maybe you could do something like this:
let overlayImageView = UIImageView(frame: originalImageView.frame)
overlayImageView.image = UIImage(named:"yellow_noise.png")
Related
I want to extract this part. But I couldn't do it well. So I need you to tell me how to do it.
Example)
https://twitter.com/straw_berry0721/status/1596714080345415681?s=20&t=1nIbnSZ2YN2m5KZaOjO5GA
1596714080345415681
https://twitter.com/xxx/status/1595920708323999744
1595920708323999744
・my code (failed)
final result = _controller.text;
t = s.lastIndexOf('status'));
s.substring(t)
One way to get this is parse it to Uri and use its path like this:
var str =
"https://twitter.com/straw_berry0721/status/1596714080345415681?s=20&t=1nIbnSZ2YN2m5KZaOjO5GA";
Uri uri = Uri.parse(str);
print("id= ${uri.path.substring(uri.path.lastIndexOf('/') + 1)}");//id= 1596714080345415681
or as #MendelG mentions in comment you can go with regex like this:
var reg = RegExp(r'status\/(\d+)');
var result = reg.firstMatch(str)?.group(1);
print("result = $result"); // result = 1596714080345415681
You could simply extract the last shown number from URLs like https://twitter.com/xxx/status/1595920708323999744 by splitting it to a List<String> then take the last element of it, like this:
String extractLastNumber(String url) {
return url.split("/").last;
}
final extractedNumber = extractLastNumber("https://twitter.com/xxx/status/1595920708323999744");
print(extractedNumber); // "1595920708323999744"
print("status: $extractedNumber"); // "status: 1595920708323999744"
Note: this will return the number as String, if you want to get it as an int number you could use the int.tryParse() method like this:
print(int.tryParse(extractedNumber)); // 1595920708323999744
I'm using Raphael's wheelnav.js and would like to use a SVG I already have, containing two seperate paths, as a spreader. I have found examples on customizing the slices, using functions already existing in wheelnav to draw with, but not on how to customize the spreader, using a custom/existing SVG.
Thanks in advance!
There is an imgsrc feature, where you can use your existing SVG.
var wheel = new wheelnav("divWheel");
wheel.spreaderEnable = true;
wheel.spreaderInTitle = "imgsrc:intitle.svg";
wheel.spreaderOutTitle = "imgsrc:outtitle.svg";
wheel.spreaderOutTitleHeight = 50;
wheel.spreaderInTitleHeight = 35;
wheel.spreaderRadius = 0;
wheel.createWheel(["This", "is", "a", "sample"]);
I am reading my data through a web service that returns a percentage as a string and I need to format it properly in my app. Currently I receive an error message that reads "Argument labels '(_:)' do not match any available overloads".
Suggestions on how to resolve this issue?
if let dUnInsured = result[0]["UnInsured"] as? String, let doubleNum = Double(dUnInsured) {
let sUnInsured = dollarFormatter.string(from: (NSDecimalNumber(Decimal(doubleNum))))!
self.inUninsured.text = sUnInsured
}
Try like this way.
if let dUnInsured = result[0]["UnInsured"] as? String, let doubleNum = Double(dUnInsured) {
let sUnInsured = dollarFormatter.string(from: (NSNumber(value: doubleNum)))!
self.inUninsured.text = sUnInsured
}
I'm new baby for Video Processing use Swift 3. I try to merge multiple videos with AVAssetExportSession, and using AVVideoCompositionCoreAnimationTool to add overlay for final video.
The problem is sometimes the final video is perfect, but sometimes it just give me a black video with sound only even I didn't change anything :(
Anybody who ran into that problem same me please give an idea, thanks!
let mixComposition: AVMutableComposition = AVMutableComposition()
//Add assets here
let mainComposition: AVMutableVideoComposition = AVMutableVideoComposition(propertiesOf: mixComposition)
mainComposition.frameDuration = CMTimeMake(1, 30)
mainComposition.renderSize = renderSize
mainComposition.renderScale = 1.0
mainComposition.animationTool = AVVideoCompositionCoreAnimationTool(postProcessingAsVideoLayer: videoLayer, in: parentLayer)
mainComposition.instructions = instructions
let exportSession: AVAssetExportSession = AVAssetExportSession(asset: mixComposition, presetName: AVAssetExportPresetHighestQuality)!
exportSession.videoComposition = mainComposition
exportSession.audioMix = audioMix
exportSession.outputURL = outputURL
exportSession.outputFileType = AVFileTypeMPEG4
exportSession.shouldOptimizeForNetworkUse = true
exportSession.exportAsynchronously {
// Ended here
}
I'm new here!
I have an NSArray like this ("file01_header","file01_body", "file01_xxx", ... ,"file02_header", ...).
I filter it and get 2 distinct NSArrays:
Array_header ("file01_header","file02_header",...)
Array_body
("file01_body", "file02_body", ...)
now I have to subtract from Array_header all the items that have a corresponding one in Array_body, because not all items have a fileNN_body for the fileNN_header in the original array, and I have to give the Array_header as output with only items that has no corresponding body.
How can I do this?
Thanks!!
If you're using swift you can filter pretty easily using a closure and some minor string-fu.
Here's an example:
let funkyArray = ["file01_header","file01_body", "file01_xxx", "file02_header","file03_xxx"]
let headerFilterClosure : (String) -> Bool = {fileName in
if fileName.containsString("header") {
let fileBase = fileName.componentsSeparatedByString("_")[0]
let fileBodyName = "\(fileBase)_body"
if funkyArray.contains(fileBodyName) {
return true
}
}
return false
}
funkyArray.filter(headerFilterClosure)
I think a better long term solution would be to not have such a funky array and use a data structure or at least a tuple with options to manage your file info.
Best,
Josh