我正在使用Auk lib在滑块中显示我的图像,我需要为每个图像设置描述。我怎么能这么做呢?现在我正在尝试下载图像,然后在其上设置描述:
override func viewDidLoad() {
super.viewDidLoad()
for picture in LogInViewController.dictionaryForSlider
{
//scrollView.auk.show(url: picture.key, accessibilityLabel: picture.value)
let downloadedPic: UIImage = self.downloadImage(urlStr: picture.key)
let newPic: UIImage = self.textToImage(drawText: picture.value as NSString, inImage: downloadedPic, atPoint: CGPoint(x: 10, y: 10))
scrollView.auk.show(image: newPic)
}
}
func textToImage(drawText text: NSString, inImage image: UIImage, atPoint point: CGPoint) -> UIImage {
let textColor = UIColor.white
let textFont = UIFont(name: "Helvetica Bold", size: 12)!
let scale = UIScreen.main.scale
UIGraphicsBeginImageContextWithOptions(image.size, false, scale)
let textFontAttributes = [
NSFontAttributeName: textFont,
NSForegroundColorAttributeName: textColor,
] as [String : Any]
image.draw(in: CGRect(origin: CGPoint.zero, size: image.size))
let rect = CGRect(origin: point, size: image.size)
text.draw(in: rect, withAttributes: textFontAttributes)
let newImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return newImage!
}
func downloadImage(urlStr: String) -> UIImage {
var img: UIImage? = nil
var imgURL: NSURL = NSURL(string: urlStr)!
let request: NSURLRequest = NSURLRequest(url: imgURL as URL)
NSURLConnection.sendAsynchronousRequest(
request as URLRequest, queue: OperationQueue.main,
completionHandler: { response,data,error in
if error == nil {
img = UIImage(data: data!)
}
})
return img!
}
但我收到了这个错误:
2017-03-25 08:02:04.627615 app1 [314:25451]致命错误:意外 在解包可选值时发现nil
在这个字符串上:
return img!
我该如何解决?或者是否有其他简单的方法来设置描述图像?
答案 0 :(得分:0)
我只使用UIScrollViewDelegate处理它而没有任何额外的libs / GB代码XD
#include <iostream>
#include "string.h"
using namespace std;
struct A {
char* a;
};
int main()
{
struct A *x;
x->a = "soumya";
char* str = "soumya";
cout<<str<<endl<<(char*)x->a<<endl;
// if(strcmp(x->a,str)!=0)
// {
// cout<<"not same"<<endl;
// }
return 0;
}