相关疑难解决方法(0)

在Swift上从URL加载/下载图像

我想从我的应用程序中的URL加载一个图像,所以我首先尝试使用Objective-C然后使用Swift,我有一个编译错误:

'imageWithData'不可用:使用对象构造'UIImage(data :)'

我的功能:

@IBOutlet var imageView : UIImageView

override func viewDidLoad() {
    super.viewDidLoad()

    var url:NSURL = NSURL.URLWithString("http://myURL/ios8.png")
    var data:NSData = NSData.dataWithContentsOfURL(url, options: nil, error: nil)

    imageView.image = UIImage.imageWithData(data)// Error here
}
Run Code Online (Sandbox Code Playgroud)

在Objective-C中:

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURL *url = [NSURL URLWithString:(@"http://myURL/ios8.png")];
    NSData *data = [NSData dataWithContentsOfURL:url];

    _imageView.image = [UIImage imageWithData: data];
    _labelURL.text = @"http://www.quentinroussat.fr/assets/img/iOS%20icon's%20Style/ios8.png";
 }
Run Code Online (Sandbox Code Playgroud)

有人可以解释一下为什么imageWithData:它不适用于Swift,我该如何解决这个问题.

nsurl uiimage ios swift

387
推荐指数
19
解决办法
45万
查看次数

将UIImage的大小调整为200x200pt/px

我一直在努力调整图像大小.基本上我已经弄明白了: 如何缩小UIImage并使其同时变得脆弱/锐利而不是模糊?

这似乎是一个合法的解决方案,但不知何故,它无法正常工作.

我的应用程序使用相机胶卷中的照片.这张照片应调整到大约200x200,而宽度很重要,而不是高度.

不幸的是,我没有示例代码,因为我在愤怒中放弃了关于非工作解决方案,对不起.

uiimage ios swift

78
推荐指数
8
解决办法
8万
查看次数

以编程方式创建按钮并设置背景图像

当我尝试在Swift中创建按钮并设置背景图像时:

let button   = UIButton.buttonWithType(UIButtonType.System) as UIButton
    button.frame = CGRectMake(100, 100, 100, 100)
    button.setImage(IMAGE, forState: UIControlState.Normal)
    button.addTarget(self, action: "btnTouched:", forControlEvents: UIControlEvents.TouchUpInside)

    self.view.addSubview(button)
Run Code Online (Sandbox Code Playgroud)

我总是得到一个错误:" 无法将表达式的'Void'转换为'UIImage'类型 ".

uibutton ios swift

72
推荐指数
6
解决办法
14万
查看次数

如何让用户使用Swift选择图像?

我正在用Swift编写我的第一个iOS应用程序(仅限iPhone).主应用程序视图应允许用户从照片库中选择图像.

我找到了以下ViewController.swift的示例代码:

class ViewController: UIImagePickerController, UINavigationControllerDelegate, UIImagePickerControllerDelegate  {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {

        var imagePickerController = UIImagePickerController()
        imagePickerController.delegate = self
        imagePickerController.sourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum
        imagePickerController.allowsEditing = true
        self.presentViewController(imagePickerController, animated: true, completion: { imageP in

        })
    }


    func imagePickerController(picker: UIImagePickerController!, didFinishPickingImage image: UIImage!, editingInfo: …
Run Code Online (Sandbox Code Playgroud)

uiimagepickercontroller ios swift

69
推荐指数
7
解决办法
10万
查看次数

如何将代码目标c转换为Swift以保存图像?

我在其他帖子中看到过这段代码,用于保存图片:

  // Create path.
 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,      NSUserDomainMask, YES);
 NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Image.png"];

// Save image.
[UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
Run Code Online (Sandbox Code Playgroud)

我正在尝试转换为swift以保存带有avfoundatioin的图片但我不知道类型NSDocumentDirectory和NSUserDomainMask这里如何转换这个?

谢谢!!

path avfoundation nsdocumentdirectory swift

10
推荐指数
1
解决办法
8936
查看次数

UIColor 和 CIColor 它们如何比较以及拥有其中两个的目的是什么?

最近我遇到了一些尝试获取 UIColor 的 CIColor 属性失败的代码。UIColor 被初始化为一个简单的 [UIColor blackColor] 并试图获得它的 CIColor 引发了异常。

CIColor *aCIColor = [[UIColor blackColor] CIColor]; //fails
Run Code Online (Sandbox Code Playgroud)

CIColor 和 UIColor 有什么区别,为什么会发生这种情况?

objective-c uicolor ios

2
推荐指数
1
解决办法
2052
查看次数

swift中UIImage、CIImage和CGImage有什么区别

我对何时使用 UIImage、CIImage 和 CGI​​mage 感到困惑

它们之间有什么区别?我什么时候可以使用它们?

ios swift

0
推荐指数
1
解决办法
3157
查看次数