开发者

Passing a UISlider value into stringByEvaluatingJavaScriptFromString?

开发者 https://www.devze.com 2023-04-08 11:32 出处:网络
I have a UISlider and I\'m trying to pass its value into a window.scrollBy string. Basically, I\'m attempting user-configurable auto-scrolling of web content.

I have a UISlider and I'm trying to pass its value into a window.scrollBy string. Basically, I'm attempting user-configurable auto-scrolling of web content.

The actual scrolling is working, but I'm unable to pass a value into the JavaScript by using the normal %f and , method.

[_webView stringByEvaluatingJavaScriptFromString:@"window.scrollBy(0,5);"];

I'm using the above, and I'd like the '5' to be substituted with the value of the slider.

Can this be done without the need for more Java 开发者_C百科(I'm absolutely not a JavaScript programmer!)


First you have to build your javascript code using StringWithFormat:

NSString *string = [NSString stringWithFormat:@"window.scrollBy(0,%f);", slider.value];
[_webView stringByEvaluatingJavaScriptFromString:string];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号